Mercurial > hg > nginx-vendor-current
comparison src/http/ngx_http_header_filter.c @ 42:41ccba1aba45 NGINX_0_1_21
nginx 0.1.21
*) Bugfix: the ngx_http_stub_status_module showed incorrect statistics
if "rtsig" method was used or if several worker process ran on SMP.
*) Bugfix: nginx could not be built by the icc compiler on Linux or if
the zlib-1.2.x library was building from sources.
*) Bugfix: nginx could not be built on NetBSD 2.0.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 22 Feb 2005 00:00:00 +0300 |
parents | 45fe5b98a9de |
children | 6cfc63e68377 |
comparison
equal
deleted
inserted
replaced
41:4d8e7a81b3a0 | 42:41ccba1aba45 |
---|---|
115 | 115 |
116 { ngx_null_string, 0 } | 116 { ngx_null_string, 0 } |
117 }; | 117 }; |
118 | 118 |
119 | 119 |
120 static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) | 120 static ngx_int_t |
121 ngx_http_header_filter(ngx_http_request_t *r) | |
121 { | 122 { |
122 u_char *p; | 123 u_char *p; |
123 size_t len; | 124 size_t len; |
124 ngx_uint_t status, i; | 125 ngx_uint_t status, i; |
125 ngx_buf_t *b; | 126 ngx_buf_t *b; |
144 r->headers_out.last_modified_time = -1; | 145 r->headers_out.last_modified_time = -1; |
145 r->headers_out.last_modified = NULL; | 146 r->headers_out.last_modified = NULL; |
146 } | 147 } |
147 } | 148 } |
148 | 149 |
149 /* 2 is for trailing "\r\n" and 2 is for "\r\n" in the end of header */ | 150 len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1 |
150 len = sizeof("HTTP/1.x ") - 1 + 2 + 2; | 151 /* the end of the header */ |
152 + sizeof(CRLF) - 1; | |
151 | 153 |
152 /* status line */ | 154 /* status line */ |
153 | 155 |
154 if (r->headers_out.status_line.len) { | 156 if (r->headers_out.status_line.len) { |
155 len += r->headers_out.status_line.len; | 157 len += r->headers_out.status_line.len; |
277 | 279 |
278 if (header[i].key.len == 0) { | 280 if (header[i].key.len == 0) { |
279 continue; | 281 continue; |
280 } | 282 } |
281 | 283 |
282 /* 2 is for ": " and 2 is for "\r\n" */ | 284 len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len |
283 len += header[i].key.len + 2 + header[i].value.len + 2; | 285 + sizeof(CRLF) - 1; |
284 } | 286 } |
285 | 287 |
286 if (!(b = ngx_create_temp_buf(r->pool, len))) { | 288 if (!(b = ngx_create_temp_buf(r->pool, len))) { |
287 return NGX_ERROR; | 289 return NGX_ERROR; |
288 } | 290 } |
297 | 299 |
298 } else { | 300 } else { |
299 b->last = ngx_cpymem(b->last, http_codes[status].data, | 301 b->last = ngx_cpymem(b->last, http_codes[status].data, |
300 http_codes[status].len); | 302 http_codes[status].len); |
301 } | 303 } |
302 *(b->last++) = CR; *(b->last++) = LF; | 304 *b->last++ = CR; *b->last++ = LF; |
303 | 305 |
304 if (!(r->headers_out.server && r->headers_out.server->key.len)) { | 306 if (!(r->headers_out.server && r->headers_out.server->key.len)) { |
305 b->last = ngx_cpymem(b->last, server_string, sizeof(server_string) - 1); | 307 b->last = ngx_cpymem(b->last, server_string, sizeof(server_string) - 1); |
306 } | 308 } |
307 | 309 |
308 if (!(r->headers_out.date && r->headers_out.date->key.len)) { | 310 if (!(r->headers_out.date && r->headers_out.date->key.len)) { |
309 b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1); | 311 b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1); |
310 b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, | 312 b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, |
311 ngx_cached_http_time.len); | 313 ngx_cached_http_time.len); |
312 | 314 |
313 *(b->last++) = CR; *(b->last++) = LF; | 315 *b->last++ = CR; *b->last++ = LF; |
314 } | 316 } |
315 | 317 |
316 if (r->headers_out.content_length == NULL) { | 318 if (r->headers_out.content_length == NULL) { |
317 if (r->headers_out.content_length_n >= 0) { | 319 if (r->headers_out.content_length_n >= 0) { |
318 b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF, | 320 b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF, |
335 | 337 |
336 r->headers_out.content_type->value.len = b->last - p; | 338 r->headers_out.content_type->value.len = b->last - p; |
337 r->headers_out.content_type->value.data = p; | 339 r->headers_out.content_type->value.data = p; |
338 } | 340 } |
339 | 341 |
340 *(b->last++) = CR; *(b->last++) = LF; | 342 *b->last++ = CR; *b->last++ = LF; |
341 } | 343 } |
342 | 344 |
343 if (r->headers_out.location | 345 if (r->headers_out.location |
344 && r->headers_out.location->value.len | 346 && r->headers_out.location->value.len |
345 && r->headers_out.location->value.data[0] == '/') | 347 && r->headers_out.location->value.data[0] == '/') |
358 r->headers_out.location->value.len); | 360 r->headers_out.location->value.len); |
359 | 361 |
360 r->headers_out.location->value.len = b->last - p; | 362 r->headers_out.location->value.len = b->last - p; |
361 r->headers_out.location->value.data = p; | 363 r->headers_out.location->value.data = p; |
362 | 364 |
363 *(b->last++) = CR; *(b->last++) = LF; | 365 *b->last++ = CR; *b->last++ = LF; |
364 } | 366 } |
365 | 367 |
366 if (!(r->headers_out.last_modified && r->headers_out.last_modified->key.len) | 368 if (!(r->headers_out.last_modified && r->headers_out.last_modified->key.len) |
367 && r->headers_out.last_modified_time != -1) | 369 && r->headers_out.last_modified_time != -1) |
368 { | 370 { |
369 b->last = ngx_cpymem(b->last, "Last-Modified: ", | 371 b->last = ngx_cpymem(b->last, "Last-Modified: ", |
370 sizeof("Last-Modified: ") - 1); | 372 sizeof("Last-Modified: ") - 1); |
371 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time); | 373 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time); |
372 | 374 |
373 *(b->last++) = CR; *(b->last++) = LF; | 375 *b->last++ = CR; *b->last++ = LF; |
374 } | 376 } |
375 | 377 |
376 if (r->chunked) { | 378 if (r->chunked) { |
377 b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF, | 379 b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF, |
378 sizeof("Transfer-Encoding: chunked" CRLF) - 1); | 380 sizeof("Transfer-Encoding: chunked" CRLF) - 1); |
410 if (header[i].key.len == 0) { | 412 if (header[i].key.len == 0) { |
411 continue; | 413 continue; |
412 } | 414 } |
413 | 415 |
414 b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); | 416 b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); |
415 *(b->last++) = ':' ; *(b->last++) = ' ' ; | 417 *b->last++ = ':' ; *b->last++ = ' ' ; |
416 | 418 |
417 b->last = ngx_cpymem(b->last, header[i].value.data, | 419 b->last = ngx_cpymem(b->last, header[i].value.data, |
418 header[i].value.len); | 420 header[i].value.len); |
419 *(b->last++) = CR; *(b->last++) = LF; | 421 *b->last++ = CR; *b->last++ = LF; |
420 } | 422 } |
421 | 423 |
422 #if (NGX_DEBUG) | 424 #if (NGX_DEBUG) |
423 *(b->last) = '\0'; | 425 *b->last = '\0'; |
424 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%s\n", b->pos); | 426 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%s\n", b->pos); |
425 #endif | 427 #endif |
426 | 428 |
427 /* the end of HTTP header */ | 429 /* the end of HTTP header */ |
428 *(b->last++) = CR; *(b->last++) = LF; | 430 *b->last++ = CR; *b->last++ = LF; |
429 | 431 |
430 r->header_size = b->last - b->pos; | 432 r->header_size = b->last - b->pos; |
431 | 433 |
432 if (r->header_only) { | 434 if (r->header_only) { |
433 b->last_buf = 1; | 435 b->last_buf = 1; |
442 | 444 |
443 return ngx_http_write_filter(r, ln); | 445 return ngx_http_write_filter(r, ln); |
444 } | 446 } |
445 | 447 |
446 | 448 |
447 static ngx_int_t ngx_http_header_filter_init(ngx_cycle_t *cycle) | 449 static ngx_int_t |
450 ngx_http_header_filter_init(ngx_cycle_t *cycle) | |
448 { | 451 { |
449 ngx_http_top_header_filter = ngx_http_header_filter; | 452 ngx_http_top_header_filter = ngx_http_header_filter; |
450 | 453 |
451 return NGX_OK; | 454 return NGX_OK; |
452 } | 455 } |