comparison src/http/ngx_http_header_filter.c @ 67:5a7d1aaa1618

nginx-0.0.1-2003-03-11-23:38:13 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 11 Mar 2003 20:38:13 +0000
parents 34d647deb1da
children e43f406e4525
comparison
equal deleted inserted replaced
66:4876cd4a36bb 67:5a7d1aaa1618
46 46
47 47
48 static ngx_str_t http_codes[] = { 48 static ngx_str_t http_codes[] = {
49 49
50 ngx_string("200 OK"), 50 ngx_string("200 OK"),
51 #if 0 51
52 { 6, "200 OK" }, 52 ngx_string("301 Moved Permanently"),
53 #endif 53 ngx_string("302 Moved Temporarily"),
54 54 ngx_null_string, /* 303 */
55 { 21, "301 Moved Permanently" }, 55 ngx_string("304 Not Modified"),
56 { 21, "302 Moved Temporarily" }, 56
57 { 0, NULL }, 57 ngx_string("400 Bad Request"),
58 { 16, "304 Not Modified" }, 58 ngx_null_string, /* 401 */
59 59 ngx_null_string, /* 402 */
60 { 15, "400 Bad Request" }, 60 ngx_string("403 Forbidden"),
61 { 0, NULL }, 61 ngx_string("404 Not Found"),
62 { 0, NULL }, 62 ngx_null_string, /* 405 */
63 { 13, "403 Forbidden" }, 63 ngx_null_string, /* 406 */
64 { 13, "404 Not Found" }, 64 ngx_null_string, /* 407 */
65 65 ngx_string("408 Request Time-out"),
66 { 25, "500 Internal Server Error" } 66 ngx_null_string, /* 409 */
67 ngx_null_string, /* 410 */
68 ngx_string("411 Length Required"),
69 ngx_null_string, /* 412 */
70 ngx_string("413 Request Entity Too Large"),
71 ngx_null_string, /* "414 Request-URI Too Large" but we never send it
72 because we treat such requests as HTTP/0.9 requests
73 and send only the body without the header */
74 ngx_null_string, /* 415 */
75 ngx_string("416 Requested Range Not Satisfiable"),
76
77 ngx_string("500 Internal Server Error"),
78 ngx_string("501 Method Not Implemented"),
79 ngx_string("502 Bad Gateway"),
80 ngx_string("503 Service Temporarily Unavailable"),
81 ngx_string("504 Gateway Time-out")
67 }; 82 };
68 83
69 84
70 85
71 static int ngx_http_header_filter(ngx_http_request_t *r) 86 static int ngx_http_header_filter(ngx_http_request_t *r)
122 } else if (r->headers_out.status < NGX_HTTP_INTERNAL_SERVER_ERROR) { 137 } else if (r->headers_out.status < NGX_HTTP_INTERNAL_SERVER_ERROR) {
123 status = r->headers_out.status - NGX_HTTP_BAD_REQUEST + 1 + 4; 138 status = r->headers_out.status - NGX_HTTP_BAD_REQUEST + 1 + 4;
124 139
125 } else { 140 } else {
126 status = r->headers_out.status 141 status = r->headers_out.status
127 - NGX_HTTP_INTERNAL_SERVER_ERROR + 1 + 4 + 5; 142 - NGX_HTTP_INTERNAL_SERVER_ERROR + 1 + 4 + 17;
128 } 143 }
129 144
130 len += http_codes[status].len; 145 len += http_codes[status].len;
131 } 146 }
132 147
179 } 194 }
180 195
181 ngx_test_null(h, ngx_create_temp_hunk(r->pool, len, 0, 64), NGX_ERROR); 196 ngx_test_null(h, ngx_create_temp_hunk(r->pool, len, 0, 64), NGX_ERROR);
182 197
183 /* "HTTP/1.x " */ 198 /* "HTTP/1.x " */
184 ngx_memcpy(h->last.mem, "HTTP/1.1 ", 9); 199 ngx_memcpy(h->last, "HTTP/1.1 ", 9);
185 h->last.mem += 9; 200 h->last += 9;
186 201
187 /* status line */ 202 /* status line */
188 if (r->headers_out.status_line.len) { 203 if (r->headers_out.status_line.len) {
189 ngx_memcpy(h->last.mem, r->headers_out.status_line.data, 204 ngx_memcpy(h->last, r->headers_out.status_line.data,
190 r->headers_out.status_line.len); 205 r->headers_out.status_line.len);
191 h->last.mem += r->headers_out.status_line.len; 206 h->last += r->headers_out.status_line.len;
192 207
193 } else { 208 } else {
194 ngx_memcpy(h->last.mem, http_codes[status].data, 209 ngx_memcpy(h->last, http_codes[status].data,
195 http_codes[status].len); 210 http_codes[status].len);
196 h->last.mem += http_codes[status].len; 211 h->last += http_codes[status].len;
197 } 212 }
198 *(h->last.mem++) = CR; *(h->last.mem++) = LF; 213 *(h->last++) = CR; *(h->last++) = LF;
199 214
200 if (!(r->headers_out.server && r->headers_out.server->key.len)) { 215 if (!(r->headers_out.server && r->headers_out.server->key.len)) {
201 ngx_memcpy(h->last.mem, server_string, sizeof(server_string) - 1); 216 ngx_memcpy(h->last, server_string, sizeof(server_string) - 1);
202 h->last.mem += sizeof(server_string) - 1; 217 h->last += sizeof(server_string) - 1;
203 } 218 }
204 219
205 if (!(r->headers_out.date && r->headers_out.date->key.len)) { 220 if (!(r->headers_out.date && r->headers_out.date->key.len)) {
206 ngx_memcpy(h->last.mem, "Date: ", 6); 221 ngx_memcpy(h->last, "Date: ", 6);
207 h->last.mem += 6; 222 h->last += 6;
208 h->last.mem += ngx_http_get_time(h->last.mem, time(NULL)); 223 h->last += ngx_http_get_time(h->last, time(NULL));
209 *(h->last.mem++) = CR; *(h->last.mem++) = LF; 224 *(h->last++) = CR; *(h->last++) = LF;
210 } 225 }
211 226
212 /* 2^64 is 20 characters */ 227 /* 2^64 is 20 characters */
213 if (r->headers_out.content_length >= 0) { 228 if (r->headers_out.content_length >= 0) {
214 h->last.mem += ngx_snprintf(h->last.mem, 49, 229 h->last += ngx_snprintf(h->last, 49,
215 "Content-Length: " OFF_FMT CRLF, 230 "Content-Length: " OFF_FMT CRLF,
216 r->headers_out.content_length); 231 r->headers_out.content_length);
217 } 232 }
218 233
219 #if 0 234 #if 0
220 if (r->headers_out.content_type.len) { 235 if (r->headers_out.content_type.len) {
221 ngx_memcpy(h->last.mem, "Content-Type: ", 14); 236 ngx_memcpy(h->last, "Content-Type: ", 14);
222 h->last.mem += 14; 237 h->last += 14;
223 ngx_memcpy(h->last.mem, r->headers_out.content_type.data, 238 ngx_memcpy(h->last, r->headers_out.content_type.data,
224 r->headers_out.content_type.len); 239 r->headers_out.content_type.len);
225 h->last.mem += r->headers_out.content_type.len; 240 h->last += r->headers_out.content_type.len;
226 *(h->last.mem++) = CR; *(h->last.mem++) = LF; 241 *(h->last++) = CR; *(h->last++) = LF;
227 } 242 }
228 #endif 243 #endif
229 244
230 if (!(r->headers_out.last_modified 245 if (!(r->headers_out.last_modified
231 && r->headers_out.last_modified->key.len) 246 && r->headers_out.last_modified->key.len)
232 && r->headers_out.last_modified_time != -1) 247 && r->headers_out.last_modified_time != -1)
233 { 248 {
234 ngx_memcpy(h->last.mem, "Last-Modified: ", 15); 249 ngx_memcpy(h->last, "Last-Modified: ", 15);
235 h->last.mem += 15; 250 h->last += 15;
236 h->last.mem += ngx_http_get_time(h->last.mem, 251 h->last += ngx_http_get_time(h->last,
237 r->headers_out.last_modified_time); 252 r->headers_out.last_modified_time);
238 *(h->last.mem++) = CR; *(h->last.mem++) = LF; 253 *(h->last++) = CR; *(h->last++) = LF;
239 } 254 }
240 255
241 if (r->keepalive == 0) { 256 if (r->keepalive == 0) {
242 ngx_memcpy(h->last.mem, "Connection: close" CRLF, 19); 257 ngx_memcpy(h->last, "Connection: close" CRLF, 19);
243 h->last.mem += 19; 258 h->last += 19;
244 259
245 } else { 260 } else {
246 ngx_memcpy(h->last.mem, "Connection: keep-alive" CRLF, 24); 261 ngx_memcpy(h->last, "Connection: keep-alive" CRLF, 24);
247 h->last.mem += 24; 262 h->last += 24;
248 } 263 }
249 264
250 for (i = 0; i < r->headers_out.headers->nelts; i++) { 265 for (i = 0; i < r->headers_out.headers->nelts; i++) {
251 if (header[i].key.len == 0) { 266 if (header[i].key.len == 0) {
252 continue; 267 continue;
253 } 268 }
254 269
255 ngx_memcpy(h->last.mem, header[i].key.data, header[i].key.len); 270 ngx_memcpy(h->last, header[i].key.data, header[i].key.len);
256 h->last.mem += header[i].key.len; 271 h->last += header[i].key.len;
257 *(h->last.mem++) = ':' ; *(h->last.mem++) = ' ' ; 272 *(h->last++) = ':' ; *(h->last++) = ' ' ;
258 273
259 ngx_memcpy(h->last.mem, header[i].value.data, header[i].value.len); 274 ngx_memcpy(h->last, header[i].value.data, header[i].value.len);
260 h->last.mem += header[i].value.len; 275 h->last += header[i].value.len;
261 *(h->last.mem++) = CR; *(h->last.mem++) = LF; 276 *(h->last++) = CR; *(h->last++) = LF;
262 } 277 }
263 278
264 /* STUB */ 279 /* STUB */
265 *(h->last.mem) = '\0'; 280 *(h->last) = '\0';
266 ngx_log_debug(r->connection->log, "%s\n" _ h->pos.mem); 281 ngx_log_debug(r->connection->log, "%s\n" _ h->pos);
267 /**/ 282 /**/
268 283
269 /* end of HTTP header */ 284 /* end of HTTP header */
270 *(h->last.mem++) = CR; *(h->last.mem++) = LF; 285 *(h->last++) = CR; *(h->last++) = LF;
271 286
272 if (r->header_only) { 287 if (r->header_only) {
273 h->type |= NGX_HUNK_LAST; 288 h->type |= NGX_HUNK_LAST;
274 } 289 }
275 290