Mercurial > hg > nginx
comparison src/http/ngx_http_header_filter_module.c @ 2857:507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 18 May 2009 12:58:19 +0000 |
parents | e4a4c889694f |
children | 118169a8ec92 |
comparison
equal
deleted
inserted
replaced
2856:f9b5dfcc96d8 | 2857:507fc5ac9839 |
---|---|
163 ngx_buf_t *b; | 163 ngx_buf_t *b; |
164 ngx_uint_t status, i, port; | 164 ngx_uint_t status, i, port; |
165 ngx_chain_t out; | 165 ngx_chain_t out; |
166 ngx_list_part_t *part; | 166 ngx_list_part_t *part; |
167 ngx_table_elt_t *header; | 167 ngx_table_elt_t *header; |
168 ngx_connection_t *c; | |
168 ngx_http_core_loc_conf_t *clcf; | 169 ngx_http_core_loc_conf_t *clcf; |
169 ngx_http_core_srv_conf_t *cscf; | 170 ngx_http_core_srv_conf_t *cscf; |
170 struct sockaddr_in *sin; | 171 struct sockaddr_in *sin; |
171 #if (NGX_HAVE_INET6) | 172 #if (NGX_HAVE_INET6) |
172 struct sockaddr_in6 *sin6; | 173 struct sockaddr_in6 *sin6; |
307 && r->headers_out.last_modified_time != -1) | 308 && r->headers_out.last_modified_time != -1) |
308 { | 309 { |
309 len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; | 310 len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; |
310 } | 311 } |
311 | 312 |
313 c = r->connection; | |
314 | |
312 if (r->headers_out.location | 315 if (r->headers_out.location |
313 && r->headers_out.location->value.len | 316 && r->headers_out.location->value.len |
314 && r->headers_out.location->value.data[0] == '/') | 317 && r->headers_out.location->value.data[0] == '/') |
315 { | 318 { |
316 r->headers_out.location->hash = 0; | 319 r->headers_out.location->hash = 0; |
324 | 327 |
325 } else { | 328 } else { |
326 host.len = NGX_SOCKADDR_STRLEN; | 329 host.len = NGX_SOCKADDR_STRLEN; |
327 host.data = addr; | 330 host.data = addr; |
328 | 331 |
329 if (ngx_http_server_addr(r, &host) != NGX_OK) { | 332 if (ngx_connection_local_sockaddr(c, &host, 0) != NGX_OK) { |
330 return NGX_ERROR; | 333 return NGX_ERROR; |
331 } | 334 } |
332 } | 335 } |
333 | 336 |
334 switch (r->connection->local_sockaddr->sa_family) { | 337 switch (c->local_sockaddr->sa_family) { |
335 | 338 |
336 #if (NGX_HAVE_INET6) | 339 #if (NGX_HAVE_INET6) |
337 case AF_INET6: | 340 case AF_INET6: |
338 sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr; | 341 sin6 = (struct sockaddr_in6 *) c->local_sockaddr; |
339 port = ntohs(sin6->sin6_port); | 342 port = ntohs(sin6->sin6_port); |
340 break; | 343 break; |
341 #endif | 344 #endif |
342 default: /* AF_INET */ | 345 default: /* AF_INET */ |
343 sin = (struct sockaddr_in *) r->connection->local_sockaddr; | 346 sin = (struct sockaddr_in *) c->local_sockaddr; |
344 port = ntohs(sin->sin_port); | 347 port = ntohs(sin->sin_port); |
345 break; | 348 break; |
346 } | 349 } |
347 | 350 |
348 len += sizeof("Location: https://") - 1 | 351 len += sizeof("Location: https://") - 1 |
350 + r->headers_out.location->value.len + 2; | 353 + r->headers_out.location->value.len + 2; |
351 | 354 |
352 if (clcf->port_in_redirect) { | 355 if (clcf->port_in_redirect) { |
353 | 356 |
354 #if (NGX_HTTP_SSL) | 357 #if (NGX_HTTP_SSL) |
355 if (r->connection->ssl) | 358 if (c->ssl) |
356 port = (port == 443) ? 0 : port; | 359 port = (port == 443) ? 0 : port; |
357 else | 360 else |
358 #endif | 361 #endif |
359 port = (port == 80) ? 0 : port; | 362 port = (port == 80) ? 0 : port; |
360 | 363 |
509 | 512 |
510 b->last = ngx_cpymem(b->last, "Location: http", | 513 b->last = ngx_cpymem(b->last, "Location: http", |
511 sizeof("Location: http") - 1); | 514 sizeof("Location: http") - 1); |
512 | 515 |
513 #if (NGX_HTTP_SSL) | 516 #if (NGX_HTTP_SSL) |
514 if (r->connection->ssl) { | 517 if (c->ssl) { |
515 *b->last++ ='s'; | 518 *b->last++ ='s'; |
516 } | 519 } |
517 #endif | 520 #endif |
518 | 521 |
519 *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/'; | 522 *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/'; |
586 | 589 |
587 b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len); | 590 b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len); |
588 *b->last++ = CR; *b->last++ = LF; | 591 *b->last++ = CR; *b->last++ = LF; |
589 } | 592 } |
590 | 593 |
591 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 594 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
592 "%*s", (size_t) (b->last - b->pos), b->pos); | 595 "%*s", (size_t) (b->last - b->pos), b->pos); |
593 | 596 |
594 /* the end of HTTP header */ | 597 /* the end of HTTP header */ |
595 *b->last++ = CR; *b->last++ = LF; | 598 *b->last++ = CR; *b->last++ = LF; |
596 | 599 |