comparison src/http/ngx_http_header_filter_module.c @ 362:54fad6c4b555 NGINX_0_6_25

nginx 0.6.25 *) Change: now the "server_name_in_redirect" directive is used instead of the "server_name" directive's special "*" parameter. *) Change: now wildcard and regex names can be used as main name in a "server_name" directive. *) Change: the "satisfy_any" directive was replaced by the "satisfy" directive. *) Workaround: old worker processes might hog CPU after reconfiguration if they was run under Linux OpenVZ. *) Feature: the "min_delete_depth" directive. *) Bugfix: the COPY and MOVE methods did not work with single files. *) Bugfix: the ngx_http_gzip_static_module did not allow the ngx_http_dav_module to work; bug appeared in 0.6.23. *) Bugfix: socket leak in HTTPS mode if deferred accept was used. Thanks to Ben Maurer. *) Bugfix: nginx could not be built without PCRE library; bug appeared in 0.6.23.
author Igor Sysoev <http://sysoev.ru>
date Tue, 08 Jan 2008 00:00:00 +0300
parents 9121a0a91f47
children edf1cb6c328e
comparison
equal deleted inserted replaced
361:160660bad929 362:54fad6c4b555
151 static ngx_int_t 151 static ngx_int_t
152 ngx_http_header_filter(ngx_http_request_t *r) 152 ngx_http_header_filter(ngx_http_request_t *r)
153 { 153 {
154 u_char *p; 154 u_char *p;
155 size_t len; 155 size_t len;
156 ngx_str_t host;
156 ngx_buf_t *b; 157 ngx_buf_t *b;
157 ngx_uint_t status, i; 158 ngx_uint_t status, i;
158 ngx_chain_t out; 159 ngx_chain_t out;
159 ngx_list_part_t *part; 160 ngx_list_part_t *part;
160 ngx_table_elt_t *header; 161 ngx_table_elt_t *header;
161 ngx_http_core_loc_conf_t *clcf; 162 ngx_http_core_loc_conf_t *clcf;
163 ngx_http_core_srv_conf_t *cscf;
164 /* AF_INET only */
165 u_char addr[INET_ADDRSTRLEN];
162 166
163 r->header_sent = 1; 167 r->header_sent = 1;
164 168
165 if (r != r->main) { 169 if (r != r->main) {
166 return NGX_OK; 170 return NGX_OK;
276 && r->headers_out.location->value.len 280 && r->headers_out.location->value.len
277 && r->headers_out.location->value.data[0] == '/') 281 && r->headers_out.location->value.data[0] == '/')
278 { 282 {
279 r->headers_out.location->hash = 0; 283 r->headers_out.location->hash = 0;
280 284
285 if (clcf->server_name_in_redirect) {
286 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
287 host = cscf->server_name;
288
289 } else if (r->headers_in.host) {
290 host.len = r->headers_in.host_name_len;
291 host.data = r->headers_in.host->value.data;
292
293 } else {
294 host.data = addr;
295
296 if (ngx_http_server_addr(r, &host) != NGX_OK) {
297 return NGX_ERROR;
298 }
299 }
300
281 #if (NGX_HTTP_SSL) 301 #if (NGX_HTTP_SSL)
282 if (r->connection->ssl) { 302 if (r->connection->ssl) {
283 len += sizeof("Location: https://") - 1 303 len += sizeof("Location: https://") - 1
284 + r->server_name.len 304 + host.len
285 + r->headers_out.location->value.len + 2; 305 + r->headers_out.location->value.len + 2;
286 306
287 if (clcf->port_in_redirect && r->port != 443) { 307 if (clcf->port_in_redirect && r->port != 443) {
288 len += r->port_text->len; 308 len += r->port_text->len;
289 } 309 }
290 310
291 } else 311 } else
292 #endif 312 #endif
293 { 313 {
294 len += sizeof("Location: http://") - 1 314 len += sizeof("Location: http://") - 1
295 + r->server_name.len 315 + host.len
296 + r->headers_out.location->value.len + 2; 316 + r->headers_out.location->value.len + 2;
297 317
298 if (clcf->port_in_redirect && r->port != 80) { 318 if (clcf->port_in_redirect && r->port != 80) {
299 len += r->port_text->len; 319 len += r->port_text->len;
300 } 320 }
301 } 321 }
322
323 } else {
324 host.len = 0;
325 host.data = NULL;
302 } 326 }
303 327
304 if (r->chunked) { 328 if (r->chunked) {
305 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1; 329 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
306 } 330 }
426 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time); 450 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);
427 451
428 *b->last++ = CR; *b->last++ = LF; 452 *b->last++ = CR; *b->last++ = LF;
429 } 453 }
430 454
431 if (r->headers_out.location 455 if (host.data) {
432 && r->headers_out.location->value.len 456
433 && r->headers_out.location->value.data[0] == '/')
434 {
435 p = b->last + sizeof("Location: ") - 1; 457 p = b->last + sizeof("Location: ") - 1;
436 458
437 b->last = ngx_cpymem(b->last, "Location: http", 459 b->last = ngx_cpymem(b->last, "Location: http",
438 sizeof("Location: http") - 1); 460 sizeof("Location: http") - 1);
439 461
442 *b->last++ ='s'; 464 *b->last++ ='s';
443 } 465 }
444 #endif 466 #endif
445 467
446 *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/'; 468 *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
447 b->last = ngx_copy(b->last, r->server_name.data, r->server_name.len); 469 b->last = ngx_copy(b->last, host.data, host.len);
448 470
449 if (clcf->port_in_redirect) { 471 if (clcf->port_in_redirect) {
450 #if (NGX_HTTP_SSL) 472 #if (NGX_HTTP_SSL)
451 if (r->connection->ssl) { 473 if (r->connection->ssl) {
452 if (r->port != 443) { 474 if (r->port != 443) {