Klaus Demo nginx / 1966aed
axe r->port_text Igor Sysoev 11 years ago
7 changed file(s) with 65 addition(s) and 65 deletion(s). Raw diff Collapse all Expand all
16021602 static ngx_int_t
16031603 ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
16041604 {
1605 ngx_uint_t i, a, last, bind_wildcard;
1605 ngx_uint_t i, last, bind_wildcard;
16061606 ngx_listening_t *ls;
16071607 ngx_http_port_t *hport;
16081608 ngx_http_conf_addr_t *addr;
16251625 bind_wildcard = 0;
16261626 }
16271627
1628 a = 0;
1629
1630 while (a < last) {
1631
1632 if (bind_wildcard && !addr[a].bind) {
1633 a++;
1628 i = 0;
1629
1630 while (i < last) {
1631
1632 if (bind_wildcard && !addr[i].bind) {
1633 i++;
16341634 continue;
16351635 }
16361636
1637 ls = ngx_http_add_listening(cf, &addr[a]);
1637 ls = ngx_http_add_listening(cf, &addr[i]);
16381638 if (ls == NULL) {
16391639 return NGX_ERROR;
16401640 }
16461646
16471647 ls->servers = hport;
16481648
1649 for (i = ls->addr_text.len - 1; i; i--) {
1650
1651 if (ls->addr_text.data[i] == ':') {
1652 hport->port_text.len = ls->addr_text.len - i;
1653 hport->port_text.data = &ls->addr_text.data[i];
1654 break;
1655 }
1656 }
1657
1658 if (a == last - 1) {
1649 if (i == last - 1) {
16591650 hport->naddrs = last;
16601651
16611652 } else {
16621653 hport->naddrs = 1;
1663 a = 0;
1654 i = 0;
16641655 }
16651656
16661657 switch (ls->sockaddr->sa_family) {
20592059 if (c->data == r && r->postponed == NULL) {
20602060 c->data = sr;
20612061 }
2062
2063 sr->port_text = r->port_text;
20642062
20652063 sr->variables = r->variables;
20662064
199199
200200
201201 typedef struct {
202 ngx_str_t port_text;
203
204202 /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
205203 void *addrs;
206204 ngx_uint_t naddrs;
314314 break;
315315 }
316316
317 len += sizeof("Location: https://") - 1
318 + host.len
319 + r->headers_out.location->value.len + 2;
320
321 if (clcf->port_in_redirect) {
322
317323 #if (NGX_HTTP_SSL)
318 if (r->connection->ssl) {
319 len += sizeof("Location: https://") - 1
320 + host.len
321 + r->headers_out.location->value.len + 2;
322
323 if (clcf->port_in_redirect && port != 443) {
324 len += r->port_text->len;
325 }
326
327 } else
328 #endif
329 {
330 len += sizeof("Location: http://") - 1
331 + host.len
332 + r->headers_out.location->value.len + 2;
333
334 if (clcf->port_in_redirect && port != 80) {
335 len += r->port_text->len;
336 }
324 if (r->connection->ssl)
325 port = (port == 443) ? 0 : port;
326 else
327 #endif
328 port = (port == 80) ? 0 : port;
329 }
330
331 if (port) {
332 len += sizeof(":65535") - 1;
337333 }
338334
339335 } else {
491487 *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
492488 b->last = ngx_copy(b->last, host.data, host.len);
493489
494 if (clcf->port_in_redirect) {
495 #if (NGX_HTTP_SSL)
496 if (r->connection->ssl) {
497 if (port != 443) {
498 b->last = ngx_copy(b->last, r->port_text->data,
499 r->port_text->len);
500 }
501 } else
502 #endif
503 {
504 if (port != 80) {
505 b->last = ngx_copy(b->last, r->port_text->data,
506 r->port_text->len);
507 }
508 }
490 if (port) {
491 b->last = ngx_sprintf(b->last, ":%ui", port);
509492 }
510493
511494 b->last = ngx_copy(b->last, r->headers_out.location->value.data,
299299
300300 port = c->listening->servers;
301301
302 r->port_text = &port->port_text;
303
304302 r->connection = c;
305303
306304 if (port->naddrs > 1) {
383383 ngx_http_post_subrequest_t *post_subrequest;
384384 ngx_http_posted_request_t *posted_requests;
385385
386 ngx_str_t *port_text; /* ":80" */
387386 ngx_http_virtual_names_t *virtual_names;
388387
389388 ngx_int_t phase_handler;
955955 ngx_http_variable_server_port(ngx_http_request_t *r,
956956 ngx_http_variable_value_t *v, uintptr_t data)
957957 {
958 v->len = r->port_text->len - 1;
959 v->valid = 1;
960 v->no_cacheable = 0;
961 v->not_found = 0;
962 v->data = r->port_text->data + 1;
958 ngx_uint_t port;
959 struct sockaddr_in *sin;
960 #if (NGX_HAVE_INET6)
961 struct sockaddr_in6 *sin6;
962 #endif
963
964 v->len = 0;
965 v->valid = 1;
966 v->no_cacheable = 0;
967 v->not_found = 0;
968
969 if (ngx_http_server_addr(r, NULL) != NGX_OK) {
970 return NGX_ERROR;
971 }
972
973 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
974 if (v->data == NULL) {
975 return NGX_ERROR;
976 }
977
978 switch (r->connection->local_sockaddr->sa_family) {
979
980 #if (NGX_HAVE_INET6)
981 case AF_INET6:
982 sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
983 port = ntohs(sin6->sin6_port);
984 break;
985 #endif
986
987 default: /* AF_INET */
988 sin = (struct sockaddr_in *) r->connection->local_sockaddr;
989 port = ntohs(sin->sin_port);
990 break;
991 }
992
993 if (port > 0 && port < 65536) {
994 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
995 }
963996
964997 return NGX_OK;
965998 }