comparison src/http/ngx_http_header_filter_module.c @ 2529:339da812982c

axe r->port
author Igor Sysoev <igor@sysoev.ru>
date Mon, 23 Feb 2009 21:19:35 +0000
parents 2e91aecb9e57
children 5b9b270ea16f
comparison
equal deleted inserted replaced
2528:c1975ccd0215 2529:339da812982c
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_str_t host;
157 ngx_buf_t *b; 157 ngx_buf_t *b;
158 ngx_uint_t status, i; 158 ngx_uint_t status, i, port;
159 ngx_chain_t out; 159 ngx_chain_t out;
160 ngx_list_part_t *part; 160 ngx_list_part_t *part;
161 ngx_table_elt_t *header; 161 ngx_table_elt_t *header;
162 ngx_connection_t *c;
162 ngx_http_core_loc_conf_t *clcf; 163 ngx_http_core_loc_conf_t *clcf;
163 ngx_http_core_srv_conf_t *cscf; 164 ngx_http_core_srv_conf_t *cscf;
165 struct sockaddr_in *sin;
166 #if (NGX_HAVE_INET6)
167 struct sockaddr_in6 *sin6;
168 #endif
164 u_char addr[NGX_SOCKADDR_STRLEN]; 169 u_char addr[NGX_SOCKADDR_STRLEN];
165 170
166 r->header_sent = 1; 171 r->header_sent = 1;
167 172
168 if (r != r->main) { 173 if (r != r->main) {
295 if (ngx_http_server_addr(r, &host) != NGX_OK) { 300 if (ngx_http_server_addr(r, &host) != NGX_OK) {
296 return NGX_ERROR; 301 return NGX_ERROR;
297 } 302 }
298 } 303 }
299 304
305 c = r->connection;
306
307 switch (c->local_sockaddr->sa_family) {
308
309 #if (NGX_HAVE_INET6)
310 case AF_INET6:
311 sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
312 port = sin6->sin6_port;
313 break;
314 #endif
315 default: /* AF_INET */
316 sin = (struct sockaddr_in *) c->local_sockaddr;
317 port = sin->sin_port;
318 break;
319 }
320
300 #if (NGX_HTTP_SSL) 321 #if (NGX_HTTP_SSL)
301 if (r->connection->ssl) { 322 if (r->connection->ssl) {
302 len += sizeof("Location: https://") - 1 323 len += sizeof("Location: https://") - 1
303 + host.len 324 + host.len
304 + r->headers_out.location->value.len + 2; 325 + r->headers_out.location->value.len + 2;
305 326
306 if (clcf->port_in_redirect && r->port != 443) { 327 if (clcf->port_in_redirect && port != 443) {
307 len += r->port_text->len; 328 len += r->port_text->len;
308 } 329 }
309 330
310 } else 331 } else
311 #endif 332 #endif
312 { 333 {
313 len += sizeof("Location: http://") - 1 334 len += sizeof("Location: http://") - 1
314 + host.len 335 + host.len
315 + r->headers_out.location->value.len + 2; 336 + r->headers_out.location->value.len + 2;
316 337
317 if (clcf->port_in_redirect && r->port != 80) { 338 if (clcf->port_in_redirect && port != 80) {
318 len += r->port_text->len; 339 len += r->port_text->len;
319 } 340 }
320 } 341 }
321 342
322 } else { 343 } else {
323 host.len = 0; 344 host.len = 0;
324 host.data = NULL; 345 host.data = NULL;
346 port = 0;
325 } 347 }
326 348
327 if (r->chunked) { 349 if (r->chunked) {
328 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1; 350 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
329 } 351 }
474 b->last = ngx_copy(b->last, host.data, host.len); 496 b->last = ngx_copy(b->last, host.data, host.len);
475 497
476 if (clcf->port_in_redirect) { 498 if (clcf->port_in_redirect) {
477 #if (NGX_HTTP_SSL) 499 #if (NGX_HTTP_SSL)
478 if (r->connection->ssl) { 500 if (r->connection->ssl) {
479 if (r->port != 443) { 501 if (port != 443) {
480 b->last = ngx_copy(b->last, r->port_text->data, 502 b->last = ngx_copy(b->last, r->port_text->data,
481 r->port_text->len); 503 r->port_text->len);
482 } 504 }
483 } else 505 } else
484 #endif 506 #endif
485 { 507 {
486 if (r->port != 80) { 508 if (port != 80) {
487 b->last = ngx_copy(b->last, r->port_text->data, 509 b->last = ngx_copy(b->last, r->port_text->data,
488 r->port_text->len); 510 r->port_text->len);
489 } 511 }
490 } 512 }
491 } 513 }