[PATCH v4 08/12] nxt_http_static_iterate(): generalize code

Alejandro Colomar alx.manpages at gmail.com
Thu Dec 23 19:25:05 UTC 2021


Separate into separate blocks of code the initialization of the
var query, and the final action, to allow for a simpler patch that
allows using variables for the 'index'.

Add a nxt_bool_t shr_is_const variable to allow for a similar
idx_is_const, and improve readability.

Signed-off-by: Alejandro Colomar <alx.manpages at gmail.com>
Cc: Nginx Unit <unit at nginx.org>
Cc: "Valentin V. Bartenev" <vbart at nginx.com>
Cc: Zhidao HONG <z.hong at f5.com>
Cc: Igor Sysoev <igor at sysoev.ru>
Cc: Oisin Canty <o.canty at f5.com>
---
 src/nxt_http_static.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index b443a54..2a176d0 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -226,6 +226,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r,
     nxt_int_t                ret;
     nxt_http_static_conf_t   *conf;
     nxt_http_static_share_t  *share;
+    nxt_bool_t               shr_is_const;
 
     conf = ctx->action->u.conf;
 
@@ -255,9 +256,19 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r,
 #endif
 #endif /* NXT_DEBUG */
 
+    shr_is_const = share->is_const;
+
+    if (!shr_is_const) {
+        ret = nxt_var_query_init(&r->var_query, r, r->mem_pool);
+        if (nxt_slow_path(ret != NXT_OK)) {
+            nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
+            return;
+        }
+    }
+
     ctx->index = conf->index;
 
-    if (share->is_const) {
+    if (shr_is_const) {
         nxt_var_raw(share->var, &ctx->share);
 
 #if (NXT_HAVE_OPENAT2)
@@ -266,15 +277,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r,
         }
 #endif
 
-        nxt_http_static_send_ready(task, r, ctx);
-
     } else {
-        ret = nxt_var_query_init(&r->var_query, r, r->mem_pool);
-        if (nxt_slow_path(ret != NXT_OK)) {
-            nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
-            return;
-        }
-
         nxt_var_query(task, r->var_query, share->var, &ctx->share);
 
 #if (NXT_HAVE_OPENAT2)
@@ -282,11 +285,16 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r,
             nxt_var_query(task, r->var_query, conf->chroot, &ctx->chroot);
         }
 #endif
+    }
+
+    if (shr_is_const) {
+        nxt_http_static_send_ready(task, r, ctx);
 
+    } else {
         nxt_var_query_resolve(task, r->var_query, ctx,
                               nxt_http_static_send_ready,
                               nxt_http_static_var_error);
-     }
+    }
 }
 
 
-- 
2.34.1



More information about the unit mailing list