[njs] HTTP: throwing an exception in r.internalRedirect() while filtering.

Dmitry Volyntsev xeioex at nginx.com
Sat May 27 02:15:54 UTC 2023


details:   https://hg.nginx.org/njs/rev/05c7f0b31856
branches:  
changeset: 2135:05c7f0b31856
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri May 26 19:13:39 2023 -0700
description:
HTTP: throwing an exception in r.internalRedirect() while filtering.

A user is notified explicitly that r.internalRedirect()
is not supported in filters.

diffstat:

 nginx/ngx_http_js_module.c |  6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diffs (23 lines):

diff -r 398f4de34fe7 -r 05c7f0b31856 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Wed May 24 22:04:38 2023 -0700
+++ b/nginx/ngx_http_js_module.c	Fri May 26 19:13:39 2023 -0700
@@ -950,6 +950,7 @@ ngx_http_js_header_filter(ngx_http_reque
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
 
+    ctx->filter = 1;
     pending = njs_vm_pending(ctx->vm);
 
     rc = ngx_js_call(ctx->vm, &jlcf->header_filter, r->connection->log,
@@ -2433,6 +2434,11 @@ ngx_http_js_ext_internal_redirect(njs_vm
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
 
+    if (ctx->filter) {
+        njs_vm_error(vm, "internalRedirect cannot be called while filtering");
+        return NJS_ERROR;
+    }
+
     if (ngx_js_string(vm, njs_arg(args, nargs, 1), &uri) != NGX_OK) {
         njs_vm_error(vm, "failed to convert uri arg");
         return NJS_ERROR;


More information about the nginx-devel mailing list