[njs] Support of undefined return from stream body filter.

Roman Arutyunyan arut at nginx.com
Tue Jan 31 17:23:52 UTC 2017


details:   http://hg.nginx.org/njs/rev/67d4bcb5823f
branches:  
changeset: 308:67d4bcb5823f
user:      Roman Arutyunyan <arut at nginx.com>
date:      Tue Jan 31 20:22:01 2017 +0300
description:
Support of undefined return from stream body filter.

diffstat:

 nginx/ngx_stream_js_module.c |  38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)

diffs (52 lines):

diff -r e9c89068140d -r 67d4bcb5823f nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Fri Jan 27 16:45:34 2017 +0300
+++ b/nginx/ngx_stream_js_module.c	Tue Jan 31 20:22:01 2017 +0300
@@ -503,28 +503,30 @@ ngx_stream_js_body_filter(ngx_stream_ses
             return NGX_ERROR;
         }
 
-        if (njs_vm_retval(ctx->vm, &value) != NJS_OK) {
-            return NGX_ERROR;
-        }
-
-        ngx_log_debug2(NGX_LOG_DEBUG_STREAM, c->log, 0,
-                       "js return value: \"%*s\"",
-                       value.length, value.start);
-
-        if (value.length) {
-            rc = ngx_atoi(value.start, value.length);
-
-            if (rc != NGX_OK && rc != -NGX_ERROR) {
-                ngx_log_error(NGX_LOG_ERR, c->log, 0,
-                              "unexpected js return code: \"%*s\"",
-                              value.length, value.start);
+        if (ctx->vm->retval.type != NJS_VOID) {
+            if (njs_vm_retval(ctx->vm, &value) != NJS_OK) {
                 return NGX_ERROR;
             }
 
-            rc = -rc;
+            ngx_log_debug2(NGX_LOG_DEBUG_STREAM, c->log, 0,
+                           "js return value: \"%*s\"",
+                           value.length, value.start);
 
-            if (rc == NGX_ERROR) {
-                return NGX_ERROR;
+            if (value.length) {
+                rc = ngx_atoi(value.start, value.length);
+
+                if (rc != NGX_OK && rc != -NGX_ERROR) {
+                    ngx_log_error(NGX_LOG_ERR, c->log, 0,
+                                  "unexpected js return code: \"%*s\"",
+                                  value.length, value.start);
+                    return NGX_ERROR;
+                }
+
+                rc = -rc;
+
+                if (rc == NGX_ERROR) {
+                    return NGX_ERROR;
+                }
             }
         }
 


More information about the nginx-devel mailing list