use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
This commit is contained in:
parent
01bd8881cc
commit
6c8087a9ed
6 changed files with 17 additions and 76 deletions
|
@ -390,12 +390,13 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
|
|||
|
||||
} else {
|
||||
if (conf->service == NGX_CONF_UNSET) {
|
||||
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c = r->connection;
|
||||
|
||||
if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
switch (c->local_sockaddr->sa_family) {
|
||||
|
||||
#if (NGX_HAVE_INET6)
|
||||
|
|
|
@ -1828,68 +1828,6 @@ ngx_http_auth_basic_user(ngx_http_request_t *r)
|
|||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s)
|
||||
{
|
||||
socklen_t len;
|
||||
ngx_uint_t addr;
|
||||
ngx_connection_t *c;
|
||||
u_char sa[NGX_SOCKADDRLEN];
|
||||
struct sockaddr_in *sin;
|
||||
#if (NGX_HAVE_INET6)
|
||||
ngx_uint_t i;
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
|
||||
c = r->connection;
|
||||
|
||||
switch (c->local_sockaddr->sa_family) {
|
||||
|
||||
#if (NGX_HAVE_INET6)
|
||||
case AF_INET6:
|
||||
sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
|
||||
|
||||
for (addr = 0, i = 0; addr == 0 && i < 16; i++) {
|
||||
addr |= sin6->sin6_addr.s6_addr[i];
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
default: /* AF_INET */
|
||||
sin = (struct sockaddr_in *) c->local_sockaddr;
|
||||
addr = sin->sin_addr.s_addr;
|
||||
break;
|
||||
}
|
||||
|
||||
if (addr == 0) {
|
||||
|
||||
len = NGX_SOCKADDRLEN;
|
||||
|
||||
if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) {
|
||||
ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c->local_sockaddr = ngx_palloc(r->connection->pool, len);
|
||||
if (c->local_sockaddr == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c->local_socklen = len;
|
||||
ngx_memcpy(c->local_sockaddr, &sa, len);
|
||||
}
|
||||
|
||||
if (s == NULL) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, 0);
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
#if (NGX_HTTP_GZIP)
|
||||
|
||||
ngx_int_t
|
||||
|
|
|
@ -440,7 +440,6 @@ ngx_int_t ngx_http_set_exten(ngx_http_request_t *r);
|
|||
u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
|
||||
size_t *root_length, size_t reserved);
|
||||
ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
|
||||
ngx_int_t ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s);
|
||||
#if (NGX_HTTP_GZIP)
|
||||
ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
|
||||
#endif
|
||||
|
|
|
@ -165,6 +165,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
ngx_chain_t out;
|
||||
ngx_list_part_t *part;
|
||||
ngx_table_elt_t *header;
|
||||
ngx_connection_t *c;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
struct sockaddr_in *sin;
|
||||
|
@ -309,6 +310,8 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
|
||||
}
|
||||
|
||||
c = r->connection;
|
||||
|
||||
if (r->headers_out.location
|
||||
&& r->headers_out.location->value.len
|
||||
&& r->headers_out.location->value.data[0] == '/')
|
||||
|
@ -326,21 +329,21 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
host.len = NGX_SOCKADDR_STRLEN;
|
||||
host.data = addr;
|
||||
|
||||
if (ngx_http_server_addr(r, &host) != NGX_OK) {
|
||||
if (ngx_connection_local_sockaddr(c, &host, 0) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
switch (r->connection->local_sockaddr->sa_family) {
|
||||
switch (c->local_sockaddr->sa_family) {
|
||||
|
||||
#if (NGX_HAVE_INET6)
|
||||
case AF_INET6:
|
||||
sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
|
||||
sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
|
||||
port = ntohs(sin6->sin6_port);
|
||||
break;
|
||||
#endif
|
||||
default: /* AF_INET */
|
||||
sin = (struct sockaddr_in *) r->connection->local_sockaddr;
|
||||
sin = (struct sockaddr_in *) c->local_sockaddr;
|
||||
port = ntohs(sin->sin_port);
|
||||
break;
|
||||
}
|
||||
|
@ -352,7 +355,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
if (clcf->port_in_redirect) {
|
||||
|
||||
#if (NGX_HTTP_SSL)
|
||||
if (r->connection->ssl)
|
||||
if (c->ssl)
|
||||
port = (port == 443) ? 0 : port;
|
||||
else
|
||||
#endif
|
||||
|
@ -511,7 +514,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
sizeof("Location: http") - 1);
|
||||
|
||||
#if (NGX_HTTP_SSL)
|
||||
if (r->connection->ssl) {
|
||||
if (c->ssl) {
|
||||
*b->last++ ='s';
|
||||
}
|
||||
#endif
|
||||
|
@ -588,7 +591,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||
*b->last++ = CR; *b->last++ = LF;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
||||
"%*s", (size_t) (b->last - b->pos), b->pos);
|
||||
|
||||
/* the end of HTTP header */
|
||||
|
|
|
@ -310,7 +310,7 @@ ngx_http_init_request(ngx_event_t *rev)
|
|||
* is required to determine a server address
|
||||
*/
|
||||
|
||||
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
|
||||
if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
|
||||
ngx_http_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -938,7 +938,7 @@ ngx_http_variable_server_addr(ngx_http_request_t *r,
|
|||
s.len = NGX_SOCKADDR_STRLEN;
|
||||
s.data = addr;
|
||||
|
||||
if (ngx_http_server_addr(r, &s) != NGX_OK) {
|
||||
if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
@ -974,7 +974,7 @@ ngx_http_variable_server_port(ngx_http_request_t *r,
|
|||
v->no_cacheable = 0;
|
||||
v->not_found = 0;
|
||||
|
||||
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
|
||||
if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue