[njs] HTTP: avoid creating empty request_body buffer in r.subrequest().

Dmitry Volyntsev xeioex at nginx.com
Tue Feb 26 13:32:37 UTC 2019


details:   https://hg.nginx.org/njs/rev/40b6f1030873
branches:  
changeset: 801:40b6f1030873
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Feb 26 16:16:08 2019 +0300
description:
HTTP: avoid creating empty request_body buffer in r.subrequest().

This fixes #101 issue on Github.

diffstat:

 nginx/ngx_http_js_module.c |  34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)

diffs (46 lines):

diff -r d49837819721 -r 40b6f1030873 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Mon Feb 25 19:00:56 2019 +0300
+++ b/nginx/ngx_http_js_module.c	Tue Feb 26 16:16:08 2019 +0300
@@ -1869,24 +1869,26 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
             goto memory_error;
         }
 
-        rb->bufs = ngx_alloc_chain_link(r->pool);
-        if (rb->bufs == NULL) {
-            goto memory_error;
+        if (body_arg.length != 0) {
+            rb->bufs = ngx_alloc_chain_link(r->pool);
+            if (rb->bufs == NULL) {
+                goto memory_error;
+            }
+
+            rb->bufs->next = NULL;
+
+            rb->bufs->buf = ngx_calloc_buf(r->pool);
+            if (rb->bufs->buf == NULL) {
+                goto memory_error;
+            }
+
+            rb->bufs->buf->memory = 1;
+            rb->bufs->buf->last_buf = 1;
+
+            rb->bufs->buf->pos = body_arg.start;
+            rb->bufs->buf->last = body_arg.start + body_arg.length;
         }
 
-        rb->bufs->next = NULL;
-
-        rb->bufs->buf = ngx_calloc_buf(r->pool);
-        if (rb->bufs->buf == NULL) {
-            goto memory_error;
-        }
-
-        rb->bufs->buf->memory = 1;
-        rb->bufs->buf->last_buf = 1;
-
-        rb->bufs->buf->pos = body_arg.start;
-        rb->bufs->buf->last = body_arg.start + body_arg.length;
-
         sr->request_body = rb;
         sr->headers_in.content_length_n = body_arg.length;
         sr->headers_in.chunked = 0;


More information about the nginx-devel mailing list