[nginx] Upstream: added the ngx_http_upstream_resolved_t.name field.

Ruslan Ermilov ru at nginx.com
Mon Oct 31 20:39:51 UTC 2016


details:   http://hg.nginx.org/nginx/rev/d1d0dd69a419
branches:  
changeset: 6785:d1d0dd69a419
user:      Ruslan Ermilov <ru at nginx.com>
date:      Mon Oct 31 18:33:33 2016 +0300
description:
Upstream: added the ngx_http_upstream_resolved_t.name field.

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.

diffstat:

 src/http/modules/ngx_http_fastcgi_module.c   |  6 ++----
 src/http/modules/ngx_http_proxy_module.c     |  6 ++----
 src/http/modules/ngx_http_scgi_module.c      |  6 ++----
 src/http/modules/ngx_http_uwsgi_module.c     |  6 ++----
 src/http/ngx_http_upstream.h                 |  1 +
 src/http/ngx_http_upstream_round_robin.c     |  2 +-
 src/stream/ngx_stream_proxy_module.c         |  6 ++----
 src/stream/ngx_stream_upstream.h             |  1 +
 src/stream/ngx_stream_upstream_round_robin.c |  2 +-
 9 files changed, 14 insertions(+), 22 deletions(-)

diffs (141 lines):

diff -r 1af120241cde -r d1d0dd69a419 src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/http/modules/ngx_http_fastcgi_module.c	Mon Oct 31 18:33:33 2016 +0300
@@ -769,13 +769,11 @@ ngx_http_fastcgi_eval(ngx_http_request_t
     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;
 
diff -r 1af120241cde -r d1d0dd69a419 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c	Mon Oct 31 18:33:33 2016 +0300
@@ -1011,13 +1011,11 @@ ngx_http_proxy_eval(ngx_http_request_t *
     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;
 
diff -r 1af120241cde -r d1d0dd69a419 src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/http/modules/ngx_http_scgi_module.c	Mon Oct 31 18:33:33 2016 +0300
@@ -565,13 +565,11 @@ ngx_http_scgi_eval(ngx_http_request_t *r
     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;
 
diff -r 1af120241cde -r d1d0dd69a419 src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/http/modules/ngx_http_uwsgi_module.c	Mon Oct 31 18:33:33 2016 +0300
@@ -767,13 +767,11 @@ ngx_http_uwsgi_eval(ngx_http_request_t *
     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;
 
diff -r 1af120241cde -r d1d0dd69a419 src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/http/ngx_http_upstream.h	Mon Oct 31 18:33:33 2016 +0300
@@ -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;
diff -r 1af120241cde -r d1d0dd69a419 src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/http/ngx_http_upstream_round_robin.c	Mon Oct 31 18:33:33 2016 +0300
@@ -337,7 +337,7 @@ ngx_http_upstream_create_round_robin_pee
     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;
diff -r 1af120241cde -r d1d0dd69a419 src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/stream/ngx_stream_proxy_module.c	Mon Oct 31 18:33:33 2016 +0300
@@ -581,13 +581,11 @@ ngx_stream_proxy_eval(ngx_stream_session
     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;
 
diff -r 1af120241cde -r d1d0dd69a419 src/stream/ngx_stream_upstream.h
--- a/src/stream/ngx_stream_upstream.h	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/stream/ngx_stream_upstream.h	Mon Oct 31 18:33:33 2016 +0300
@@ -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;
diff -r 1af120241cde -r d1d0dd69a419 src/stream/ngx_stream_upstream_round_robin.c
--- a/src/stream/ngx_stream_upstream_round_robin.c	Mon Oct 31 18:33:31 2016 +0300
+++ b/src/stream/ngx_stream_upstream_round_robin.c	Mon Oct 31 18:33:33 2016 +0300
@@ -344,7 +344,7 @@ ngx_stream_upstream_create_round_robin_p
     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;



More information about the nginx-devel mailing list