[PATCH v3 00/12] Static: Implement new "index" option

Alejandro Colomar (man-pages) alx.manpages at gmail.com
Thu Dec 23 19:14:23 UTC 2021


Hi Valentin,

On 12/19/21 16:47, Valentin V. Bartenev wrote:
>> <src/nxt_http_static.c> and how all this iteration works?
> [..]
> 
> Variable strings intrepolation is asynchronous, so it may take any amount
> of time, that's why we don't interpolate them until they are needed.
> 
> And that's also why it can't be just a loop, as we can't block the processing
> thread on waiting for variable resolution.  Instead we schedule an event, and
> provide a callback, that will be called once the variable string interpolation
> completes.
> 
> "share" works exactly as it's documented:
> 
>   - https://unit.nginx.org/configuration/#static-files
> 
> it takes the first value from an array in nxt_http_static_iterate() and
> schedules interpolation query (by nxt_var_query_resolve() call) with all
> the other options, that will be needed to process.
> 
> Once they are interpolated, the nxt_http_static_send_ready() callback is
> called, which tries to open the configured file path.
> 
> If opening fails, then nxt_http_static_next() is called, which switches to the
> next value of "share" option by incrementing index, and starts interpolation
> of it by calling nxt_http_static_iterate() again.
> 
> When "share" and "index" both configured as arrays, then it interates over
> "share" trying to serve file.  If the file path points to a directory, then
> it iterates over "index" trying to serve index file.  If no index file is
> found for a particular "share" path, it continues to interate over "share"
> array.  If it's a directory path again, it iterates over "index" array for
> that path again.
> 
> So each time, when the "share" value points to a directory, it should interate
> over indexes until the working one will be found.

Thanks, this helped a lot :)
I finished, and will send you v4 in a moment, which I expect to be the 
last one.

Finishing it was easy; I only needed the following changes compared to v3:

diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index 91bf26e..30b7fd6 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -711,7 +711,10 @@ nxt_http_static_next(nxt_task_t *task, 
nxt_http_request_t *r,
      action = ctx->action;
      conf = action->u.conf;

-    ctx->share_idx++;
+    ctx->index_idx = (ctx->index_idx + 1) % conf->nindices;
+    if (ctx->index_idx == 0) {
+        ctx->share_idx++;
+    }

      if (ctx->share_idx < conf->nshares) {
          nxt_http_static_iterate(task, r, ctx);


Kind regards,
Alex

> 
> --
> Valentin
> 
> 
> 

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/


More information about the unit mailing list