axe r->port_text
This commit is contained in:
parent
268c329649
commit
a7b6c2f33a
7 changed files with 58 additions and 58 deletions
|
@ -1603,7 +1603,7 @@ ngx_http_cmp_dns_wildcards(const void *one, const void *two)
|
|||
static ngx_int_t
|
||||
ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
|
||||
{
|
||||
ngx_uint_t i, a, last, bind_wildcard;
|
||||
ngx_uint_t i, last, bind_wildcard;
|
||||
ngx_listening_t *ls;
|
||||
ngx_http_port_t *hport;
|
||||
ngx_http_conf_addr_t *addr;
|
||||
|
@ -1626,16 +1626,16 @@ ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
|
|||
bind_wildcard = 0;
|
||||
}
|
||||
|
||||
a = 0;
|
||||
i = 0;
|
||||
|
||||
while (a < last) {
|
||||
while (i < last) {
|
||||
|
||||
if (bind_wildcard && !addr[a].bind) {
|
||||
a++;
|
||||
if (bind_wildcard && !addr[i].bind) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ls = ngx_http_add_listening(cf, &addr[a]);
|
||||
ls = ngx_http_add_listening(cf, &addr[i]);
|
||||
if (ls == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
@ -1647,21 +1647,12 @@ ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
|
|||
|
||||
ls->servers = hport;
|
||||
|
||||
for (i = ls->addr_text.len - 1; i; i--) {
|
||||
|
||||
if (ls->addr_text.data[i] == ':') {
|
||||
hport->port_text.len = ls->addr_text.len - i;
|
||||
hport->port_text.data = &ls->addr_text.data[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (a == last - 1) {
|
||||
if (i == last - 1) {
|
||||
hport->naddrs = last;
|
||||
|
||||
} else {
|
||||
hport->naddrs = 1;
|
||||
a = 0;
|
||||
i = 0;
|
||||
}
|
||||
|
||||
switch (ls->sockaddr->sa_family) {
|
||||
|
|
|
@ -2061,8 +2061,6 @@ ngx_http_subrequest(ngx_http_request_t *r,
|
|||
c->data = sr;
|
||||
}
|
||||
|
||||
sr->port_text = r->port_text;
|
||||
|
||||
sr->variables = r->variables;
|
||||
|
||||
sr->log_handler = r->log_handler;
|
||||
|
|
|
@ -200,8 +200,6 @@ typedef struct {
|
|||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t port_text;
|
||||
|
||||
/* ngx_http_in_addr_t or ngx_http_in6_addr_t */
|
||||
void *addrs;
|
||||
ngx_uint_t naddrs;
|
||||
|
|
|
@ -315,26 +315,22 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
break;
|
||||
}
|
||||
|
||||
len += sizeof("Location: https://") - 1
|
||||
+ host.len
|
||||
+ r->headers_out.location->value.len + 2;
|
||||
|
||||
if (clcf->port_in_redirect) {
|
||||
|
||||
#if (NGX_HTTP_SSL)
|
||||
if (r->connection->ssl) {
|
||||
len += sizeof("Location: https://") - 1
|
||||
+ host.len
|
||||
+ r->headers_out.location->value.len + 2;
|
||||
|
||||
if (clcf->port_in_redirect && port != 443) {
|
||||
len += r->port_text->len;
|
||||
}
|
||||
|
||||
} else
|
||||
if (r->connection->ssl)
|
||||
port = (port == 443) ? 0 : port;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
len += sizeof("Location: http://") - 1
|
||||
+ host.len
|
||||
+ r->headers_out.location->value.len + 2;
|
||||
port = (port == 80) ? 0 : port;
|
||||
}
|
||||
|
||||
if (clcf->port_in_redirect && port != 80) {
|
||||
len += r->port_text->len;
|
||||
}
|
||||
if (port) {
|
||||
len += sizeof(":65535") - 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -492,21 +488,8 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
*b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
|
||||
b->last = ngx_copy(b->last, host.data, host.len);
|
||||
|
||||
if (clcf->port_in_redirect) {
|
||||
#if (NGX_HTTP_SSL)
|
||||
if (r->connection->ssl) {
|
||||
if (port != 443) {
|
||||
b->last = ngx_copy(b->last, r->port_text->data,
|
||||
r->port_text->len);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (port != 80) {
|
||||
b->last = ngx_copy(b->last, r->port_text->data,
|
||||
r->port_text->len);
|
||||
}
|
||||
}
|
||||
if (port) {
|
||||
b->last = ngx_sprintf(b->last, ":%ui", port);
|
||||
}
|
||||
|
||||
b->last = ngx_copy(b->last, r->headers_out.location->value.data,
|
||||
|
|
|
@ -300,8 +300,6 @@ ngx_http_init_request(ngx_event_t *rev)
|
|||
|
||||
port = c->listening->servers;
|
||||
|
||||
r->port_text = &port->port_text;
|
||||
|
||||
r->connection = c;
|
||||
|
||||
if (port->naddrs > 1) {
|
||||
|
|
|
@ -384,7 +384,6 @@ struct ngx_http_request_s {
|
|||
ngx_http_post_subrequest_t *post_subrequest;
|
||||
ngx_http_posted_request_t *posted_requests;
|
||||
|
||||
ngx_str_t *port_text; /* ":80" */
|
||||
ngx_http_virtual_names_t *virtual_names;
|
||||
|
||||
ngx_int_t phase_handler;
|
||||
|
|
|
@ -956,11 +956,44 @@ static ngx_int_t
|
|||
ngx_http_variable_server_port(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data)
|
||||
{
|
||||
v->len = r->port_text->len - 1;
|
||||
ngx_uint_t port;
|
||||
struct sockaddr_in *sin;
|
||||
#if (NGX_HAVE_INET6)
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
|
||||
v->len = 0;
|
||||
v->valid = 1;
|
||||
v->no_cacheable = 0;
|
||||
v->not_found = 0;
|
||||
v->data = r->port_text->data + 1;
|
||||
|
||||
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
|
||||
if (v->data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
switch (r->connection->local_sockaddr->sa_family) {
|
||||
|
||||
#if (NGX_HAVE_INET6)
|
||||
case AF_INET6:
|
||||
sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
|
||||
port = ntohs(sin6->sin6_port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default: /* AF_INET */
|
||||
sin = (struct sockaddr_in *) r->connection->local_sockaddr;
|
||||
port = ntohs(sin->sin_port);
|
||||
break;
|
||||
}
|
||||
|
||||
if (port > 0 && port < 65536) {
|
||||
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue