Skip to content

Commit

Permalink
Upstream: added the ngx_http_upstream_resolved_t.name field.
Browse files Browse the repository at this point in the history
This fixes inconsistency in what is stored in the "host" field.
Normally it would contain the "host" part of the parsed URL
(e.g., proxy_pass with variables), but for the case of an
implicit upstream specified with literal address it contained
the text representation of the socket address (that is, host
including port for IP).

Now the "host" field always contains the "host" part of the URL,
while the text representation of the socket address is stored
in the newly added "name" field.

The ngx_http_upstream_create_round_robin_peer() function was
modified accordingly in a way to be compatible with the code
that does not know about the new "name" field.

The "stream" code was similarly modified except for not adding
compatibility in ngx_stream_upstream_create_round_robin_peer().

This change is also a prerequisite for the next change.
  • Loading branch information
mdocguard committed Oct 31, 2016
1 parent 4e1720b commit 3fae83a
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/http/modules/ngx_http_fastcgi_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,11 @@ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
if (url.addrs) {
u->resolved->sockaddr = url.addrs[0].sockaddr;
u->resolved->socklen = url.addrs[0].socklen;
u->resolved->name = url.addrs[0].name;
u->resolved->naddrs = 1;
u->resolved->host = url.addrs[0].name;

} else {
u->resolved->host = url.host;
}

u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

Expand Down
6 changes: 2 additions & 4 deletions src/http/modules/ngx_http_proxy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,13 +1011,11 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
if (url.addrs) {
u->resolved->sockaddr = url.addrs[0].sockaddr;
u->resolved->socklen = url.addrs[0].socklen;
u->resolved->name = url.addrs[0].name;
u->resolved->naddrs = 1;
u->resolved->host = url.addrs[0].name;

} else {
u->resolved->host = url.host;
}

u->resolved->host = url.host;
u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
u->resolved->no_port = url.no_port;

Expand Down
6 changes: 2 additions & 4 deletions src/http/modules/ngx_http_scgi_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,11 @@ ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf)
if (url.addrs) {
u->resolved->sockaddr = url.addrs[0].sockaddr;
u->resolved->socklen = url.addrs[0].socklen;
u->resolved->name = url.addrs[0].name;
u->resolved->naddrs = 1;
u->resolved->host = url.addrs[0].name;

} else {
u->resolved->host = url.host;
}

u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

Expand Down
6 changes: 2 additions & 4 deletions src/http/modules/ngx_http_uwsgi_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,11 @@ ngx_http_uwsgi_eval(ngx_http_request_t *r, ngx_http_uwsgi_loc_conf_t * uwcf)
if (url.addrs) {
u->resolved->sockaddr = url.addrs[0].sockaddr;
u->resolved->socklen = url.addrs[0].socklen;
u->resolved->name = url.addrs[0].name;
u->resolved->naddrs = 1;
u->resolved->host = url.addrs[0].name;

} else {
u->resolved->host = url.host;
}

u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

Expand Down
1 change: 1 addition & 0 deletions src/http/ngx_http_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ typedef struct {

struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t name;

ngx_resolver_ctx_t *ctx;
} ngx_http_upstream_resolved_t;
Expand Down
2 changes: 1 addition & 1 deletion src/http/ngx_http_upstream_round_robin.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
if (ur->sockaddr) {
peer[0].sockaddr = ur->sockaddr;
peer[0].socklen = ur->socklen;
peer[0].name = ur->host;
peer[0].name = ur->name.data ? ur->name : ur->host;
peer[0].weight = 1;
peer[0].effective_weight = 1;
peer[0].current_weight = 0;
Expand Down
6 changes: 2 additions & 4 deletions src/stream/ngx_stream_proxy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,11 @@ ngx_stream_proxy_eval(ngx_stream_session_t *s,
if (url.addrs) {
u->resolved->sockaddr = url.addrs[0].sockaddr;
u->resolved->socklen = url.addrs[0].socklen;
u->resolved->name = url.addrs[0].name;
u->resolved->naddrs = 1;
u->resolved->host = url.addrs[0].name;

} else {
u->resolved->host = url.host;
}

u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

Expand Down
1 change: 1 addition & 0 deletions src/stream/ngx_stream_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef struct {

struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t name;

ngx_resolver_ctx_t *ctx;
} ngx_stream_upstream_resolved_t;
Expand Down
2 changes: 1 addition & 1 deletion src/stream/ngx_stream_upstream_round_robin.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ ngx_stream_upstream_create_round_robin_peer(ngx_stream_session_t *s,
if (ur->sockaddr) {
peer[0].sockaddr = ur->sockaddr;
peer[0].socklen = ur->socklen;
peer[0].name = ur->host;
peer[0].name = ur->name;
peer[0].weight = 1;
peer[0].effective_weight = 1;
peer[0].current_weight = 0;
Expand Down

0 comments on commit 3fae83a

Please sign in to comment.