[PATCH] RFC: ngx_http_upstream_process_upgraded: Allocate buffers also for data from upstream

Thomas Glanzmann thomas at glanzmann.de
Sat Mar 15 22:11:51 UTC 2014


While using the ugprade funcationality of nginx to tunnel propiertary
HTTP commands I noticed that data were only passing through from
upstream to downstream but not the other way around. The reason for that
was that no receive buffers for downstream were allocated. Normally the
receiver buffers for upstream are allocated in
ngx_http_upstream_process_header. In my case they were not because I
upgrade the connection before exchanging any data. Maybe you consider
this for upstream.
---
 src/http/ngx_http_upstream.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index cf9ca0d..5ff1f2b 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2644,20 +2644,20 @@ ngx_http_upstream_process_upgraded(ngx_http_request_t *r,
             b->end = b->last;
             do_write = 1;
         }
+    }
 
+    if (b->start == NULL) {
+        b->start = ngx_palloc(r->pool, u->conf->buffer_size);
         if (b->start == NULL) {
-            b->start = ngx_palloc(r->pool, u->conf->buffer_size);
-            if (b->start == NULL) {
-                ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
-                return;
-            }
-
-            b->pos = b->start;
-            b->last = b->start;
-            b->end = b->start + u->conf->buffer_size;
-            b->temporary = 1;
-            b->tag = u->output.tag;
+            ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
+            return;
         }
+
+        b->pos = b->start;
+        b->last = b->start;
+        b->end = b->start + u->conf->buffer_size;
+        b->temporary = 1;
+        b->tag = u->output.tag;
     }
 
     for ( ;; ) {
-- 
1.7.10.4



More information about the nginx mailing list