From vbart at nginx.com Thu Dec 2 19:23:40 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Thu, 02 Dec 2021 22:23:40 +0300 Subject: Unit 1.26.1 release Message-ID: <5519319.DvuYhMxLoT@vbart-laptop> Hi, I'm glad to announce a new release of NGINX Unit. This is a minor bugfix release that aims to eliminate some annoying regressions revealed after the release of Unit 1.26.0 two weeks ago. Notably, the shared OPcache implementation in that release required introducing some major architectural changes, but our functional tests didn't catch some regressions caused by these changes. Still, thanks to our active community, the issues were reported shortly after the release, and now we can provide an updated version. We will also improve our functional testing to avoid such regressions in the future. The most painful and visible one was that sometimes Unit daemon couldn't completely exit, leaving some zombie processes. However, the second attempt to stop it always succeeded. Also, some DragonFly BSD kernel interfaces are seemingly broken, preventing the Unit daemon from functioning, so we disabled their use when compiling for DragonFly BSD. Changes with Unit 1.26.1 02 Dec 2021 *) Bugfix: occasionally, the Unit daemon was unable to fully terminate; the bug had appeared in 1.26.0. *) Bugfix: a prototype process could crash on an application process exit; the bug had appeared in 1.26.0. *) Bugfix: the router process crashed on reconfiguration if "access_log" was configured without listeners. *) Bugfix: a segmentation fault occurred in the PHP module if chdir() or fastcgi_finish_request() was called in the OPcache preloading script. *) Bugfix: fatal errors on DragonFly BSD; the bug had appeared in 1.26.0. To know more about the bunch of changes introduced in Unit 1.26 and the roadmap for 1.27, please see the previous announcement: - https://mailman.nginx.org/pipermail/unit/2021-November/000288.html Thank you again for keeping your finger on the pulse, reporting issues and submitting feature requests via our GitHub issue tracker: - https://github.com/nginx/unit/issues Stay tuned! wbr, Valentin V. Bartenev From scottvankalken at gmail.com Wed Dec 8 00:25:10 2021 From: scottvankalken at gmail.com (Scott van Kalken) Date: Wed, 8 Dec 2021 11:25:10 +1100 Subject: CORS Message-ID: Hey all, wondering about handling CORS. East to do with NGINX but i?m wondering what the story is with doing this in unit without fronting unit with NGINX. Is the ability to set headers for CORS available today or is it planned yet? -------------- next part -------------- An HTML attachment was scrubbed... URL: From vbart at nginx.com Wed Dec 8 14:56:36 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Wed, 08 Dec 2021 17:56:36 +0300 Subject: [PATCH] Remove unused static function: nxt_http_static() In-Reply-To: <7eeb76cd-698e-3989-dced-25bdf558c4ce@gmail.com> References: <20211207000118.40562-1-alx.manpages@gmail.com> <2243561.ElGaqSPkdT@vbart-laptop> <7eeb76cd-698e-3989-dced-25bdf558c4ce@gmail.com> Message-ID: <2235644.ElGaqSPkdT@vbart-laptop> On Wednesday, 8 December 2021 12:40:55 MSK Alejandro Colomar (man-pages) wrote: [..] > > I'll ask some other doubts that I have about that file: > > - What does ctx mean? context... in this case it's a static file serving context, that contains realtime data needed to pass across static file serving functions for a particular request. > - What's the difference between conf and ctx? > conf is configuration data that is initilized when user uploads a new configuration; it contains configuration parameters. ctx is initilized when a new request is handled; it contains realtime data needed to serve this request. > > Obviously, if you remove it, you even won't be able to compile the code. > > > > Yes. However, I had a previous compile error from a clean checkout, so > I didn't even bother compiling my modified version yet. > > I reported it to the wrong list too :/ Now I resent it to the correct > list, and also to you. Could you have a look at that? [..] I'll try to reproduce on Debian Sid VM and come back to you with a solution, or with a question if I won't be able to reproduce. wbr, Valentin V. Bartenev From vbart at nginx.com Wed Dec 8 21:37:14 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Thu, 09 Dec 2021 00:37:14 +0300 Subject: Compilation error: [-Werror=stringop-overflow=] In-Reply-To: <94e4d3a4-4406-04e5-3b98-adf8161535d4@gmail.com> References: <94e4d3a4-4406-04e5-3b98-adf8161535d4@gmail.com> Message-ID: <2237840.ElGaqSPkdT@vbart-laptop> On Wednesday, 8 December 2021 12:16:18 MSK Alejandro Colomar (man-pages) wrote: [..] > > The error doesn't make much sense, since this file doesn't seem to be > > calling sigsetjmp(3) nor using 200 bytes of any buffer, so it looks like > > either a glibc bug, or a compiler bug. > > > > Did you see this bug before? > > I've installed Debian Sid just to reproduce it. It seems the issue is caused by mismatch between __sigsetjmp() prototypes in and system headers. So, changing their order in Unit includes resolved the issue for me: diff --git a/src/nxt_unix.h b/src/nxt_unix.h --- a/src/nxt_unix.h +++ b/src/nxt_unix.h @@ -153,6 +153,7 @@ #include #include #include +#include #include #include #include @@ -184,7 +185,6 @@ #include #include #include -#include #if (NXT_HAVE_EPOLL) #include But that doesn't look like a Unit issue, it just indicates broken toolchain in Debian Sid. So, I wouldn't recommend using unstable distribution for development, as you will end up spending time on fighting various strange and unrelated issues with the system rather than with the project. Personally I prefer to use Gentoo. It allows good balance between stability and cutting edge. wbr, Valentin V. Bartenev From vbart at nginx.com Thu Dec 9 01:54:05 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Thu, 09 Dec 2021 04:54:05 +0300 Subject: C standard in Unit In-Reply-To: <424929ea-b401-07a4-2461-1256d8cb7cb0@gmail.com> References: <424929ea-b401-07a4-2461-1256d8cb7cb0@gmail.com> Message-ID: <1729066.VLH7GnMWUR@vbart-laptop> On Thursday, 9 December 2021 03:01:11 MSK Alejandro Colomar (man-pages) wrote: > Hi Valentin, > > What's the oldest C standard you support? I'm guessing C89 by what I > see. I didn't see anything in the (Nginx) development guide. There's no intention to target specific standard. We just use what most compilers on relevant platforms are support, and don't use features we don't like, or don't see benefit. There are plenty of C99 features used in the code: - designated initializers - flexible array members - inline functions - variadic macros > > I see a few 1's where a boolean is expected (and nxt_bool_t defined as > an unsigned integer (which IMHO seems a bit dangerous, BTW)), so I guess > I shouldn't use C99's true/false, right? nxt_bool_t is only used for local variables and function parameters. It serves two purposes: 1. self-documentation, its name hits that it's expected to be a boolean flag 2. the underlying type fits into register to squeeze every bit of performance In structures the boolean flags are stored with optimal size/performance balance depending on the particular structure size and its field alignments. Such granular control would be hard to achieve using only C99 booleans. wbr, Valentin V. Bartenev From vbart at nginx.com Mon Dec 13 13:01:05 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Mon, 13 Dec 2021 16:01:05 +0300 Subject: CORS In-Reply-To: References: Message-ID: <5540382.DvuYhMxLoT@vbart-laptop> On Wednesday, 8 December 2021 03:25:10 MSK Scott van Kalken wrote: > Hey all, > > wondering about handling CORS. East to do with NGINX but i?m wondering what > the story is with doing this in unit without fronting unit with NGINX. > > Is the ability to set headers for CORS available today or is it planned yet? > Hi, Unfortunately, there's no way to alter response header fields in Unit yet. Yes, this feature definitely is in our todo. If you have any idea about how the relevant configuration should look like, please feel free to share. wbr, Valentin V. Bartenev From osa at freebsd.org.ru Wed Dec 15 04:03:05 2021 From: osa at freebsd.org.ru (Sergey A. Osokin) Date: Wed, 15 Dec 2021 07:03:05 +0300 Subject: [PATCH] update java components to their recent versions Message-ID: Hi, here's the patch to update NGINX Unit's java components to their recent versions. Thank you. -- Sergey A. Osokin -------------- next part -------------- A non-text attachment was scrubbed... Name: unit-java.diff Type: text/x-diff Size: 5980 bytes Desc: not available URL: From scottvankalken at gmail.com Thu Dec 16 01:00:45 2021 From: scottvankalken at gmail.com (Scott van Kalken) Date: Thu, 16 Dec 2021 12:00:45 +1100 Subject: CORS In-Reply-To: References: <5540382.DvuYhMxLoT@vbart-laptop> Message-ID: .....including the mailing list this time :) On Thu, 16 Dec 2021 at 11:59, Scott van Kalken wrote: > Hey Valentin, > > I don't know what everyone else would like to do with respect to CORS, but > I have found a number of use cases where it would be helpful to be able to > set response headers. > > Now, there are two things that I can think of here. > If this is for an actual application - I should be able to set response > headers in my application, so why would I ever need to explicitly do this > in unit? > > Something like this: > > @app.route('/hello', methods=["POST"])def hello(): > resp = make_response(render_template('hello.html')) > resp.headers['Access-Control-Allow-Origin'] = '*' > return resp > > > If I do that then everything should be fine. > > Where this falls down is use case #2 where I want to talk to the unit > server itself, or where I have a compiled application and don't necessarily > have the source code. > > The one that I've been focussed on recently is the "I want to talk to the > unit server itself". I've been playing around with visualising the unit > configuration, starting with some VUE bits - and also using the tree > animation from here: > https://philogb.github.io/jit/static/v20/Jit/Examples/Spacetree/example1.html > (I've been a fan of Nicolas' for some time). > > This got me thinking on the wider concepts of CORS headers. > > I am still in two minds as to whether unit itself should have this > capability or whether there should be an expectation that the application > does this. > > Open to thoughts on this - because I think it's an interesting area. > > Scott. > > > > > > > On Tue, 14 Dec 2021 at 00:01, Valentin V. Bartenev > wrote: > >> On Wednesday, 8 December 2021 03:25:10 MSK Scott van Kalken wrote: >> > Hey all, >> > >> > wondering about handling CORS. East to do with NGINX but i?m wondering >> what >> > the story is with doing this in unit without fronting unit with NGINX. >> > >> > Is the ability to set headers for CORS available today or is it planned >> yet? >> > >> >> Hi, >> >> Unfortunately, there's no way to alter response header fields in Unit yet. >> Yes, this feature definitely is in our todo. >> >> If you have any idea about how the relevant configuration should look >> like, >> please feel free to share. >> >> wbr, Valentin V. Bartenev >> >> >> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From alx.manpages at gmail.com Sat Dec 18 19:55:22 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Sat, 18 Dec 2021 20:55:22 +0100 Subject: Storing possibly-arrays as arrays Message-ID: Hi Valentin, While implementing the "index" option, I found this code, which didn't convince me: [ shr_is_array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY); conf->nshares = shr_is_array ? nxt_conf_array_elements_count(acf->share) : 1; conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) * conf->nshares); if (nxt_slow_path(conf->shares == NULL)) { return NXT_ERROR; } if (shr_is_array) { for (i = 0; i < conf->nshares; i++) { cv = nxt_conf_get_array_element(acf->share, i); nxt_conf_get_string(cv, &str); var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; } conf->shares[i].var = var; conf->shares[i].is_const = nxt_var_is_const(var); } } else { nxt_conf_get_string(acf->share, &str); var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; } conf->shares[0].var = var; conf->shares[0].is_const = nxt_var_is_const(var); } ] Most of the code is duplicated for the cases that 'share is not an array' and 'share is an array', changing just a single line. How about reorganizing the data structures so that when both a string/object and an array are a valid type .type = NXT_CONF_VLDT_* | NXT_CONF_VLDT_ARRAY, the data is _always_ stored as an array (of size 1 if it was not an array originally)? It could allow to simplify the code above to the following one: [ conf->nshares = nxt_conf_array_elements_count(acf->share); conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) * conf->nshares); if (nxt_slow_path(conf->shares == NULL)) { return NXT_ERROR; } for (i = 0; i < conf->nshares; i++) { cv = nxt_conf_get_array_element(acf->share, i); nxt_conf_get_string(cv, &str); var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; } conf->shares[i].var = var; conf->shares[i].is_const = nxt_var_is_const(var); } ] Things to consider would be: - Does any code behave differently for arrays and for strings/objects? - Does forcing strings/objects as arrays impose non-negligible performance penalties? Another alternative, but maybe not so good since it kind of defeats the difference between (nxt) arrays and non-arrays, would be to modify nxt_conf_array_elements_count() so that if (value->type != NXT_CONF_VALUE_ARRAY) { return (index == 0) ? value : NULL; } This would be similar to C pointers to variables, which can always be considered as pointers to the first element of an array of size 1. Cheers, Alex -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From alx.manpages at gmail.com Sat Dec 18 19:57:45 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Sat, 18 Dec 2021 20:57:45 +0100 Subject: Storing possibly-arrays as arrays In-Reply-To: References: Message-ID: On 12/18/21 20:55, Alejandro Colomar (man-pages) wrote: > Hi Valentin, > > While implementing the "index" option, I found this code, which didn't > convince me: > > [ > ??? shr_is_array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY); > ??? conf->nshares = shr_is_array ? > nxt_conf_array_elements_count(acf->share) > ???????????????????????????????? : 1; > ??? conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) > ?????????????????????????????????? * conf->nshares); > ??? if (nxt_slow_path(conf->shares == NULL)) { > ??????? return NXT_ERROR; > ??? } > > ??? if (shr_is_array) { > ??????? for (i = 0; i < conf->nshares; i++) { > ??????????? cv = nxt_conf_get_array_element(acf->share, i); > ??????????? nxt_conf_get_string(cv, &str); > > ??????????? var = nxt_var_compile(&str, mp, 1); > ??????????? if (nxt_slow_path(var == NULL)) { > ??????????????? return NXT_ERROR; > ??????????? } > > ??????????? conf->shares[i].var = var; > ??????????? conf->shares[i].is_const = nxt_var_is_const(var); > ??????? } > > ??? } else { > ??????? nxt_conf_get_string(acf->share, &str); > > ??????? var = nxt_var_compile(&str, mp, 1); > ??????? if (nxt_slow_path(var == NULL)) { > ??????????? return NXT_ERROR; > ??????? } > > ??????? conf->shares[0].var = var; > ??????? conf->shares[0].is_const = nxt_var_is_const(var); > ??? } > ] > > Most of the code is duplicated for the cases that 'share is not an > array' and 'share is an array', changing just a single line.? How about > reorganizing the data structures so that when both a string/object and > an array are a valid type > ????.type = NXT_CONF_VLDT_* | NXT_CONF_VLDT_ARRAY, > the data is _always_ stored as an array (of size 1 if it was not an > array originally)? > > It could allow to simplify the code above to the following one: > > [ > ??? conf->nshares = nxt_conf_array_elements_count(acf->share); > ??? conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) > ?????????????????????????????????? * conf->nshares); > ??? if (nxt_slow_path(conf->shares == NULL)) { > ??????? return NXT_ERROR; > ??? } > > ??? for (i = 0; i < conf->nshares; i++) { > ??????? cv = nxt_conf_get_array_element(acf->share, i); > ??????? nxt_conf_get_string(cv, &str); > > ??????? var = nxt_var_compile(&str, mp, 1); > ??????? if (nxt_slow_path(var == NULL)) { > ??????????? return NXT_ERROR; > ??????? } > > ??????? conf->shares[i].var = var; > ??????? conf->shares[i].is_const = nxt_var_is_const(var); > ??? } > ] > > Things to consider would be: > - Does any code behave differently for arrays and for strings/objects? > - Does forcing strings/objects as arrays impose non-negligible > performance penalties? > > Another alternative, but maybe not so good since it kind of defeats the > difference between (nxt) arrays and non-arrays, would be to modify > nxt_conf_array_elements_count() so that Oops, I meant nxt_conf_get_array_element(). > ??? if (value->type != NXT_CONF_VALUE_ARRAY) { > ??????? return (index == 0) ? value : NULL; > ??? } > This would be similar to C pointers to variables, which can always be > considered as pointers to the first element of an array of size 1. > > > Cheers, > Alex > > -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From vbart at nginx.com Sat Dec 18 20:10:30 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Sat, 18 Dec 2021 23:10:30 +0300 Subject: Storing possibly-arrays as arrays In-Reply-To: References: Message-ID: <4730459.31r3eYUQgx@vbart-laptop> On Saturday, 18 December 2021 22:55:22 MSK Alejandro Colomar (man-pages) wrote: > Hi Valentin, > > While implementing the "index" option, I found this code, which didn't > convince me: > > [ > shr_is_array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY); > conf->nshares = shr_is_array ? > nxt_conf_array_elements_count(acf->share) > : 1; > conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) > * conf->nshares); > if (nxt_slow_path(conf->shares == NULL)) { > return NXT_ERROR; > } > > if (shr_is_array) { > for (i = 0; i < conf->nshares; i++) { > cv = nxt_conf_get_array_element(acf->share, i); > nxt_conf_get_string(cv, &str); > > var = nxt_var_compile(&str, mp, 1); > if (nxt_slow_path(var == NULL)) { > return NXT_ERROR; > } > > conf->shares[i].var = var; > conf->shares[i].is_const = nxt_var_is_const(var); > } > > } else { > nxt_conf_get_string(acf->share, &str); > > var = nxt_var_compile(&str, mp, 1); > if (nxt_slow_path(var == NULL)) { > return NXT_ERROR; > } > > conf->shares[0].var = var; > conf->shares[0].is_const = nxt_var_is_const(var); > } > ] > > Most of the code is duplicated for the cases that 'share is not an > array' and 'share is an array', changing just a single line. How about > reorganizing the data structures so that when both a string/object and > an array are a valid type > .type = NXT_CONF_VLDT_* | NXT_CONF_VLDT_ARRAY, > the data is _always_ stored as an array (of size 1 if it was not an > array originally)? [..] The code you've just mentioned above is the first place where the data from a user's config is actually processed. It's not stored anywhere when NXT_CONF_VLDT_* rules validate JSON scheme. [..] > Another alternative, but maybe not so good since it kind of defeats the > difference between (nxt) arrays and non-arrays, would be to modify > nxt_conf_array_elements_count() so that > if (value->type != NXT_CONF_VALUE_ARRAY) { > return (index == 0) ? value : NULL; > } > This would be similar to C pointers to variables, which can always be > considered as pointers to the first element of an array of size 1. > That makes sense. -- Valentin From alx.manpages at gmail.com Sun Dec 19 01:01:18 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Sun, 19 Dec 2021 02:01:18 +0100 Subject: Storing possibly-arrays as arrays In-Reply-To: <4730459.31r3eYUQgx@vbart-laptop> References: <4730459.31r3eYUQgx@vbart-laptop> Message-ID: <9cbabb95-222e-3f8a-a686-815d34f477db@gmail.com> Hi Valentin, On 12/18/21 21:10, Valentin V. Bartenev wrote: >> >> Most of the code is duplicated for the cases that 'share is not an >> array' and 'share is an array', changing just a single line. How about >> reorganizing the data structures so that when both a string/object and >> an array are a valid type >> .type = NXT_CONF_VLDT_* | NXT_CONF_VLDT_ARRAY, >> the data is _always_ stored as an array (of size 1 if it was not an >> array originally)? > [..] > > The code you've just mentioned above is the first place where the data > from a user's config is actually processed. It's not stored anywhere > when NXT_CONF_VLDT_* rules validate JSON scheme. Okay, thanks! > > > [..] >> Another alternative, but maybe not so good since it kind of defeats the >> difference between (nxt) arrays and non-arrays, would be to modify >> nxt_conf_array_elements_count() so that >> if (value->type != NXT_CONF_VALUE_ARRAY) { >> return (index == 0) ? value : NULL; >> } >> This would be similar to C pointers to variables, which can always be >> considered as pointers to the first element of an array of size 1. >> > > That makes sense. Good. I added it to the patch set :) Cheers, Alex -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From alx.manpages at gmail.com Sun Dec 19 01:30:18 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:18 +0100 Subject: [PATCH v3 00/12] Static: Implement new "index" option Message-ID: <20211219013030.51372-1-alx.manpages@gmail.com> Hi Valentin, I have implemented part of the last step for adding this feature, as you proposed them: *(1) Add new "index" option, with minimal support (a string). *(2) Allow variables in the "index" option. +(3) Allow multiple filenames in the "index" option. However, there's something that I couldn't yet fully understand, which I need for this: how does the iteration of shares exactly work, how do other variables (e.g., chroot, fallback) intervene, and how is index expected to intervene in that mix. Since instead of an explicit loop there are quite some nested function calls, I couldn't manage to understand it. Could you please share some brief description of the purpose of each static function in and how all this iteration works? For this review of the patch set, I didn't yet do much testing. I passed all previously existing pytests. The only one that fails is the one I modified in patch 12 (the last one), which is to be expected, since I didn't yet write code to iterate over the indices (it's just picking the first element in the array always). If you reverse the order in the array (in the pytest) to be ["$host.html", "idontexist"] it passes the test, which at least makes me happy since the part that should still work (compared to step 2) still works. Then, there are a few extra additions (and removals) in this patch set since v2. v2: - Add support for variables in "index" - Don't move share_idx, since that caused unnecessary padding. - Use v3: - Don't use (as previously discussed). - Add a .gitignore: While doing this work, I had quite some accidents. This prevented them from happening again. I based it on the .gitignore of the Linux man-pages . - Treat non-arrays as arrays of size 1 (as discussed earlier today: ). - Simplify all of the code that can be simplified thanks to the change mentioned above (arrays of size 1). - Fix the indentation of some random lines that I found to have an incorrect indentation. - Reduce branching (especially 'else's), to improve readability. I didn't merge this change into the patch that adds the feature because there it adds too much complexity for nothing, and the patches read better separately. However, I patched it previous to the third step to simplify that patch too, so this change sits on a patch of its own better, I think. - Use const for a read-only parameter of a function. I didn't change other functions (not even in the same file), since that would mean a huuuge diff, and for consistency we would need to do it everywhere. So I only did it where I *needed* it to compile, for now. Could you please give some feedback (again) on these changes? Thanks, Alex --- Alejandro Colomar (12): .gitignore: ignore new files nxt_conf.c: Treat non-arrays as arrays of size 1 Remove special cases for non-NXT_CONF_VALUE_ARRAY Fix indentation nxt_http_static_ctx_t: rename field 'index' to 'share_idx' test_static.py: formatting fix Static: add "index" option nxt_http_static_iterate(): generalize code Static: variables in the "index" option. nxt_conf_set_string_dup(): Use 'const' for read-only parameter nxt_http_static_init(): Simplify branching Static: multiple paths in the "index" option .gitignore | 2 + docs/changes.xml | 18 ++++++ src/nxt_conf.c | 7 ++- src/nxt_conf.h | 2 +- src/nxt_conf_validation.c | 8 ++- src/nxt_gnutls.c | 4 +- src/nxt_http.h | 15 ++--- src/nxt_http_route.c | 54 +++-------------- src/nxt_http_static.c | 124 ++++++++++++++++++++++++-------------- src/nxt_main_process.c | 2 +- src/nxt_openssl.c | 24 ++------ src/nxt_router.c | 23 ++----- src/nxt_time_parse.c | 6 +- src/nxt_unit.c | 4 +- src/nxt_work_queue.h | 4 +- src/perl/nxt_perl_psgi.c | 2 +- src/python/nxt_python.c | 9 --- test/test_static.py | 18 ++++-- 18 files changed, 164 insertions(+), 162 deletions(-) create mode 100644 .gitignore -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:19 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:19 +0100 Subject: [PATCH v3 01/12] .gitignore: ignore new files In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-2-alx.manpages@gmail.com> When working with git, one has to be very careful of not adding temporary files resulting from compilation, testing, or text editors. With this .gitignore, one can add all of the changes with `git add .` without having to specify the files manually, avoiding accidents. When a new file is created and should really be added, one can add it still with the '-f' option to git-add(1). Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ed833f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore everything new by default +/* -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:20 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:20 +0100 Subject: [PATCH v3 02/12] nxt_conf.c: Treat non-arrays as arrays of size 1 In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-3-alx.manpages@gmail.com> Similar to how C pointers to variables can always be considered as pointers to the first element of an array of size 1 (see the following code for an example of how they are equivalent), treating non-NXT_CONF_VALUE_ARRAY as if they were NXT_CONF_VALUE_ARRAYs of size 1 allows for simpler and more generic code. void foo(ptrdiff_t sz, int arr[sz]) { for (ptrdiff_t i = 0; i < sz; i++) arr[i] = 0; } void bar(void) { int x; int y[1]; foo(1, &x); foo(1, y); } nxt_conf_array_elements_count(): Return a size of 1 when input is non-array, instead of causing undefined behavior. That value (1) makes sense because it will be used as the limiter of a loop that loops over the array and calls nxt_conf_get_array_element(), which will return a correct element for such loops. nxt_conf_get_array_element(): Return the input pointer unmodified (i.e., a pointer to the unique element of a hypothetical array), instead of returning NULL, which wasn't very useful. nxt_conf_array_qsort(): Since it's a no-op for non-arrays, this doesn't need to be modified. Example of (correct) usage: void baz(nxt_conf_value_t *x) { /* 'x' may or may not be a NXT_CONF_VALUE_ARRAY */ ptrdiff_t n; nxt_conf_value_t *elem; n = nxt_conf_array_elements_count(x); for (ptrdiff_t i = 0; i < n; i++) { elem = nxt_conf_get_array_element(x, i); /* do some work with 'elem' */ } } Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 1aca0a7..3f0cfa8 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -387,7 +387,7 @@ nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp, nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value) { - return value->u.array->count; + return (value->type == NXT_CONF_VALUE_ARRAY) ? value->u.array->count : 1; } @@ -736,7 +736,7 @@ nxt_conf_get_array_element(nxt_conf_value_t *value, uint32_t index) nxt_conf_array_t *array; if (value->type != NXT_CONF_VALUE_ARRAY) { - return NULL; + return (index == 0) ? value : NULL; } array = value->u.array; -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:21 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:21 +0100 Subject: [PATCH v3 03/12] Remove special cases for non-NXT_CONF_VALUE_ARRAY In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-4-alx.manpages@gmail.com> The previous commit made the functions accepting NXT_CONF_VALUE_ARRAY more generic, so that now they can handle non-arrays correctly. Modify calling code to remove special cases for arrays and non-arrays, taking special care that the path for non arrays is logically equivalent to the previous special cased code. Use the now-generic array code only. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_route.c | 45 +++-------------------------------------- src/nxt_http_static.c | 28 ++++++------------------- src/nxt_openssl.c | 24 ++++++---------------- src/nxt_router.c | 23 ++++++--------------- src/python/nxt_python.c | 9 --------- 5 files changed, 21 insertions(+), 108 deletions(-) diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 606bf26..71ebf3f 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -718,13 +718,11 @@ nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp, { size_t size; uint32_t i, n; - nxt_bool_t array; nxt_conf_value_t *ruleset_cv; nxt_http_route_table_t *table; nxt_http_route_ruleset_t *ruleset; - array = (nxt_conf_type(table_cv) == NXT_CONF_ARRAY); - n = array ? nxt_conf_array_elements_count(table_cv) : 1; + n = nxt_conf_array_elements_count(table_cv); size = sizeof(nxt_http_route_table_t) + n * sizeof(nxt_http_route_ruleset_t *); @@ -736,18 +734,6 @@ nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp, table->items = n; table->object = NXT_HTTP_ROUTE_TABLE; - if (!array) { - ruleset = nxt_http_route_ruleset_create(task, mp, table_cv, object, - case_sensitive, encoding); - if (nxt_slow_path(ruleset == NULL)) { - return NULL; - } - - table->ruleset[0] = ruleset; - - return table; - } - for (i = 0; i < n; i++) { ruleset_cv = nxt_conf_get_array_element(table_cv, i); @@ -911,13 +897,11 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp, size_t size; uint32_t i, n; nxt_int_t ret; - nxt_bool_t string; nxt_conf_value_t *value; nxt_http_route_rule_t *rule; nxt_http_route_pattern_t *pattern; - string = (nxt_conf_type(cv) != NXT_CONF_ARRAY); - n = string ? 1 : nxt_conf_array_elements_count(cv); + n = nxt_conf_array_elements_count(cv); size = sizeof(nxt_http_route_rule_t) + n * sizeof(nxt_http_route_pattern_t); rule = nxt_mp_alloc(mp, size); @@ -929,17 +913,6 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp, pattern = &rule->pattern[0]; - if (string) { - pattern[0].case_sensitive = case_sensitive; - ret = nxt_http_route_pattern_create(task, mp, cv, &pattern[0], - pattern_case, encoding); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - return rule; - } - nxt_conf_array_qsort(cv, nxt_http_pattern_compare); for (i = 0; i < n; i++) { @@ -963,13 +936,11 @@ nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp, { size_t size; uint32_t i, n; - nxt_bool_t array; nxt_conf_value_t *value; nxt_http_route_addr_rule_t *addr_rule; nxt_http_route_addr_pattern_t *pattern; - array = (nxt_conf_type(cv) == NXT_CONF_ARRAY); - n = array ? nxt_conf_array_elements_count(cv) : 1; + n = nxt_conf_array_elements_count(cv); size = sizeof(nxt_http_route_addr_rule_t) + n * sizeof(nxt_http_route_addr_pattern_t); @@ -981,16 +952,6 @@ nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp, addr_rule->items = n; - if (!array) { - pattern = &addr_rule->addr_pattern[0]; - - if (nxt_http_route_addr_pattern_parse(mp, pattern, cv) != NXT_OK) { - return NULL; - } - - return addr_rule; - } - for (i = 0; i < n; i++) { pattern = &addr_rule->addr_pattern[i]; value = nxt_conf_get_array_element(cv, i); diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 36c1ebc..6b7cee7 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -77,7 +77,6 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_mp_t *mp; nxt_str_t str; nxt_var_t *var; - nxt_bool_t array; nxt_conf_value_t *cv; nxt_http_static_conf_t *conf; @@ -91,39 +90,24 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, action->handler = nxt_http_static; action->u.conf = conf; - array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY); - conf->nshares = array ? nxt_conf_array_elements_count(acf->share) : 1; - + conf->nshares = nxt_conf_array_elements_count(acf->share); conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) * conf->nshares); if (nxt_slow_path(conf->shares == NULL)) { return NXT_ERROR; } - if (array) { - for (i = 0; i < conf->nshares; i++) { - cv = nxt_conf_get_array_element(acf->share, i); - nxt_conf_get_string(cv, &str); - - var = nxt_var_compile(&str, mp, 1); - if (nxt_slow_path(var == NULL)) { - return NXT_ERROR; - } - - conf->shares[i].var = var; - conf->shares[i].is_const = nxt_var_is_const(var); - } - - } else { - nxt_conf_get_string(acf->share, &str); + for (i = 0; i < conf->nshares; i++) { + cv = nxt_conf_get_array_element(acf->share, i); + nxt_conf_get_string(cv, &str); var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; } - conf->shares[0].var = var; - conf->shares[0].is_const = nxt_var_is_const(var); + conf->shares[i].var = var; + conf->shares[i].is_const = nxt_var_is_const(var); } #if (NXT_HAVE_OPENAT2) diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c index 1e08015..a4564f1 100644 --- a/src/nxt_openssl.c +++ b/src/nxt_openssl.c @@ -644,16 +644,10 @@ nxt_tls_ticket_keys(nxt_task_t *task, SSL_CTX *ctx, nxt_tls_init_t *tls_init, return NXT_OK; } - if (nxt_conf_type(tickets_conf) == NXT_CONF_ARRAY) { - count = nxt_conf_array_elements_count(tickets_conf); + count = nxt_conf_array_elements_count(tickets_conf); - if (count == 0) { - goto no_ticket; - } - - } else { - /* nxt_conf_type(tickets_conf) == NXT_CONF_STRING */ - count = 1; + if (count == 0) { + goto no_ticket; } #ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB @@ -673,15 +667,9 @@ nxt_tls_ticket_keys(nxt_task_t *task, SSL_CTX *ctx, nxt_tls_init_t *tls_init, i++; - if (nxt_conf_type(tickets_conf) == NXT_CONF_ARRAY) { - member = nxt_conf_get_array_element(tickets_conf, count - i); - if (member == NULL) { - break; - } - - } else { - /* nxt_conf_type(tickets_conf) == NXT_CONF_STRING */ - member = tickets_conf; + member = nxt_conf_get_array_element(tickets_conf, count - i); + if (member == NULL) { + break; } nxt_conf_get_string(member, &value); diff --git a/src/nxt_router.c b/src/nxt_router.c index 52ea0f3..b8ee0c7 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1924,25 +1924,14 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, tls_init->tickets_conf = nxt_conf_get_path(listener, &conf_tickets); - if (nxt_conf_type(certificate) == NXT_CONF_ARRAY) { - n = nxt_conf_array_elements_count(certificate); - - for (i = 0; i < n; i++) { - value = nxt_conf_get_array_element(certificate, i); - - nxt_assert(value != NULL); + n = nxt_conf_array_elements_count(certificate); + for (i = 0; i < n; i++) { + value = nxt_conf_get_array_element(certificate, i); - ret = nxt_router_conf_tls_insert(tmcf, value, skcf, - tls_init, i == 0); - if (nxt_slow_path(ret != NXT_OK)) { - goto fail; - } - } + nxt_assert(value != NULL); - } else { - /* NXT_CONF_STRING */ - ret = nxt_router_conf_tls_insert(tmcf, certificate, skcf, - tls_init, 1); + ret = nxt_router_conf_tls_insert(tmcf, value, skcf, + tls_init, i == 0); if (nxt_slow_path(ret != NXT_OK)) { goto fail; } diff --git a/src/python/nxt_python.c b/src/python/nxt_python.c index 8687c86..3edaa08 100644 --- a/src/python/nxt_python.c +++ b/src/python/nxt_python.c @@ -411,14 +411,7 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value) /* sys is a Borrowed reference. */ - if (nxt_conf_type(value) == NXT_CONF_STRING) { - n = 0; - goto value_is_string; - } - - /* NXT_CONF_ARRAY */ array = value; - n = nxt_conf_array_elements_count(array); while (n != 0) { @@ -432,8 +425,6 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value) value = nxt_conf_get_array_element(array, n); - value_is_string: - nxt_conf_get_string(value, &str); path = PyString_FromStringAndSize((char *) str.start, str.length); -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:22 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:22 +0100 Subject: [PATCH v3 04/12] Fix indentation In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-5-alx.manpages@gmail.com> Some lines (incorrectly) had an indenteation of 5 or 9 spaces instead of 4 or 8. Fix them. Found with: $ ## 5 spaces instead of 4: $ $ find src/ -type f \ |grep -n '^ [^ *]'; $ ## 9 spaces instead of 8: $ $ find src/ -type f \ |grep -l '^ [^ *]' \ |xargs grep -L '^ [^ *].*)$' \ |xargs grep -n '^ [^ *]' Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_conf_validation.c | 4 ++-- src/nxt_gnutls.c | 4 ++-- src/nxt_http.h | 14 +++++++------- src/nxt_http_route.c | 4 ++-- src/nxt_main_process.c | 2 +- src/nxt_time_parse.c | 6 +++--- src/nxt_unit.c | 4 ++-- src/nxt_work_queue.h | 4 ++-- src/perl/nxt_perl_psgi.c | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 3f068bb..7edd638 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -114,7 +114,7 @@ static nxt_int_t nxt_conf_vldt_pass(nxt_conf_validation_t *vldt, static nxt_int_t nxt_conf_vldt_return(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_share(nxt_conf_validation_t *vldt, - nxt_conf_value_t *value, void *data); + nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_share_element(nxt_conf_validation_t *vldt, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_proxy(nxt_conf_validation_t *vldt, @@ -194,7 +194,7 @@ static nxt_int_t nxt_conf_vldt_java_classpath(nxt_conf_validation_t *vldt, static nxt_int_t nxt_conf_vldt_java_option(nxt_conf_validation_t *vldt, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_upstream(nxt_conf_validation_t *vldt, - nxt_str_t *name, nxt_conf_value_t *value); + nxt_str_t *name, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_server(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_server_weight(nxt_conf_validation_t *vldt, diff --git a/src/nxt_gnutls.c b/src/nxt_gnutls.c index 4618dce..aab4699 100644 --- a/src/nxt_gnutls.c +++ b/src/nxt_gnutls.c @@ -708,11 +708,11 @@ nxt_gnutls_log_error_level(nxt_event_conn_t *c, ssize_t err) case GNUTLS_E_UNKNOWN_CIPHER_SUITE: /* -21 */ - /* Disable gnutls_bye(), because it returns GNUTLS_E_INTERNAL_ERROR. */ + /* Disable gnutls_bye(), because it returns GNUTLS_E_INTERNAL_ERROR. */ ssltls = c->u.ssltls; ssltls->no_shutdown = 1; - /* Fall through. */ + /* Fall through. */ case GNUTLS_E_UNEXPECTED_PACKET_LENGTH: /* -9 */ c->socket.error = 1000; /* Nonexistent errno code. */ diff --git a/src/nxt_http.h b/src/nxt_http.h index 02d66f5..7cef134 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -90,17 +90,17 @@ typedef union { #define nxt_http_field_name_set(_field, _name) \ do { \ - (_field)->name_length = nxt_length(_name); \ - (_field)->name = (u_char *) _name; \ + (_field)->name_length = nxt_length(_name); \ + (_field)->name = (u_char *) _name; \ } while (0) #define nxt_http_field_set(_field, _name, _value) \ do { \ - (_field)->name_length = nxt_length(_name); \ - (_field)->value_length = nxt_length(_value); \ - (_field)->name = (u_char *) _name; \ - (_field)->value = (u_char *) _value; \ + (_field)->name_length = nxt_length(_name); \ + (_field)->value_length = nxt_length(_value); \ + (_field)->name = (u_char *) _name; \ + (_field)->value = (u_char *) _value; \ } while (0) @@ -238,7 +238,7 @@ typedef struct { void (*body_read)(nxt_task_t *task, nxt_http_request_t *r); void (*local_addr)(nxt_task_t *task, nxt_http_request_t *r); void (*header_send)(nxt_task_t *task, nxt_http_request_t *r, - nxt_work_handler_t body_handler, void *data); + nxt_work_handler_t body_handler, void *data); void (*send)(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out); nxt_off_t (*body_bytes_sent)(nxt_task_t *task, nxt_http_proto_t proto); void (*discard)(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *last); diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 71ebf3f..26f0662 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -932,7 +932,7 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp, nxt_http_route_addr_rule_t * nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp, - nxt_conf_value_t *cv) + nxt_conf_value_t *cv) { size_t size; uint32_t i, n; @@ -2294,7 +2294,7 @@ nxt_http_route_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end) name = NULL; start = p + 1; - } + } } if (name != NULL) { diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 9883f04..03761a1 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -579,7 +579,7 @@ nxt_main_process_created_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) -1, msg->port_msg.stream, 0, NULL); return; } - } + } #endif diff --git a/src/nxt_time_parse.c b/src/nxt_time_parse.c index 5a32b21..94c4328 100644 --- a/src/nxt_time_parse.c +++ b/src/nxt_time_parse.c @@ -282,9 +282,9 @@ nxt_time_parse(const u_char *p, size_t len) days = days - 719527 + 31 + 28; s = (uint64_t) days * 86400 - + (nxt_uint_t) hour * 3600 - + (nxt_uint_t) min * 60 - + (nxt_uint_t) sec; + + (nxt_uint_t) hour * 3600 + + (nxt_uint_t) min * 60 + + (nxt_uint_t) sec; #if (NXT_TIME_T_SIZE <= 4) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index dac612b..32bb07a 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -5114,9 +5114,9 @@ nxt_unit_ctx_alloc(nxt_unit_ctx_t *ctx, void *data) rc = nxt_unit_ctx_init(lib, new_ctx, data); if (nxt_slow_path(rc != NXT_UNIT_OK)) { - nxt_unit_free(ctx, new_ctx); + nxt_unit_free(ctx, new_ctx); - return NULL; + return NULL; } queue_fd = -1; diff --git a/src/nxt_work_queue.h b/src/nxt_work_queue.h index 6c2d6c2..ffa21d2 100644 --- a/src/nxt_work_queue.h +++ b/src/nxt_work_queue.h @@ -16,12 +16,12 @@ struct nxt_task_s { uint32_t ident; nxt_work_t *next_work; - /* TODO: exception_handler, prev/next task, subtasks. */ + /* TODO: exception_handler, prev/next task, subtasks. */ }; #define nxt_task_next_ident() \ - ((uint32_t) nxt_atomic_fetch_add(&nxt_task_ident, 1) & 0x3FFFFFFF) + ((uint32_t) nxt_atomic_fetch_add(&nxt_task_ident, 1) & 0x3FFFFFFF) /* diff --git a/src/perl/nxt_perl_psgi.c b/src/perl/nxt_perl_psgi.c index 02555c9..e40cb5d 100644 --- a/src/perl/nxt_perl_psgi.c +++ b/src/perl/nxt_perl_psgi.c @@ -640,7 +640,7 @@ nxt_perl_psgi_env_create(PerlInterpreter *my_perl, do { \ if (nxt_slow_path((FNS) != NXT_UNIT_OK)) \ goto fail; \ - } while (0) + } while (0) #define NL(S) (S), sizeof(S)-1 -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:23 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:23 +0100 Subject: [PATCH v3 05/12] nxt_http_static_ctx_t: rename field 'index' to 'share_idx' In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-6-alx.manpages@gmail.com> Having a configurable index filename will require adding an index field to this structure. The most natural name for that field is 'index', so the current index field should be renamed to allow for that. A sensible name is 'share_idx', since it's the index of the shares array in 'nxt_http_static_conf_t'. Instead of 'share_index' I opted for the shorter 'share_idx'. Also, when 'index' allows an array of filenames in a following commit, another similar variable 'index_idx' should be created, and having a different prefix and suffix seems more readable than for example 'index_index'. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_static.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 6b7cee7..663f896 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -33,7 +33,7 @@ typedef struct { #if (NXT_HAVE_OPENAT2) nxt_str_t chroot; #endif - uint32_t index; + uint32_t share_idx; uint8_t need_body; /* 1 bit */ } nxt_http_static_ctx_t; @@ -218,7 +218,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, conf = ctx->action->u.conf; - share = &conf->shares[ctx->index]; + share = &conf->shares[ctx->share_idx]; #if (NXT_DEBUG) nxt_str_t shr; @@ -245,7 +245,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_var_raw(share->var, &ctx->share); #if (NXT_HAVE_OPENAT2) - if (conf->chroot != NULL && ctx->index == 0) { + if (conf->chroot != NULL && ctx->share_idx == 0) { nxt_var_raw(conf->chroot, &ctx->chroot); } #endif @@ -262,7 +262,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_var_query(task, r->var_query, share->var, &ctx->share); #if (NXT_HAVE_OPENAT2) - if (conf->chroot != NULL && ctx->index == 0) { + if (conf->chroot != NULL && ctx->share_idx == 0) { nxt_var_query(task, r->var_query, conf->chroot, &ctx->chroot); } #endif @@ -357,7 +357,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) nxt_uint_t resolve; nxt_http_static_share_t *share; - share = &conf->shares[ctx->index]; + share = &conf->shares[ctx->share_idx]; resolve = conf->resolve; chr = &ctx->chroot; @@ -659,9 +659,9 @@ nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r, action = ctx->action; conf = action->u.conf; - ctx->index++; + ctx->share_idx++; - if (ctx->index < conf->nshares) { + if (ctx->share_idx < conf->nshares) { nxt_http_static_iterate(task, r, ctx); return; } -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:24 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:24 +0100 Subject: [PATCH v3 06/12] test_static.py: formatting fix In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-7-alx.manpages@gmail.com> Expand indentation, to allow for the addition of an "index" configuration. This only changes whitespace/indentation. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- test/test_static.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_static.py b/test/test_static.py index 80f4c61..76668a1 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -30,7 +30,11 @@ class TestStatic(TestApplicationProto): { "listeners": {"*:7080": {"pass": "routes"}}, "routes": [ - {"action": {"share": option.temp_dir + "/assets$uri"}} + { + "action": { + "share": option.temp_dir + "/assets$uri" + } + } ], "settings": { "http": { -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:25 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:25 +0100 Subject: [PATCH v3 07/12] Static: add "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-8-alx.manpages@gmail.com> This supports a new option "index", that configures a custom index file name that will be served when a directory is requested. This initial support only allows a single fixed string. An example: { "share": "/www/data/static/$uri", "index": "lookatthis.htm" } When is requested, will be served. If the option is missing, default to "index.html". === nxt_conf_validator.c: Accept "index" as a member of "share", and make sure it is a string. === test_static.py: Rename to , to be able to test this new option, and set "index": "index_.html". Perhaps we should also add a test to check that if "index" is omitted, the default "index.html" is used. I also tried this feature in my own computer, where I tried the following: - Setting "index" to "lookatthis.htm", and check that the correct file is being served (check both a different name and a different extension). - Not setting "index", and check that is being served. - Settind "index" to an array of strings, and check that the configuration fails: { "error": "Invalid configuration.", "detail": "The \"index\" value must be a string, but not an array." } === TODO: - Multiple filenames in the 'index' option. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- docs/changes.xml | 6 ++++++ src/nxt_conf_validation.c | 3 +++ src/nxt_http.h | 1 + src/nxt_http_route.c | 5 +++++ src/nxt_http_static.c | 32 +++++++++++++++++++++++--------- test/test_static.py | 13 +++++++------ 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 8890e4d..07f3c83 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -18,6 +18,12 @@ date="" time="" packager="Andrei Belov <defan at nginx.com>"> + + +new "index" option to specify a custom index file name. + + + NGINX Unit updated to 1.27.0. diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 7edd638..bdc38b0 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -645,6 +645,9 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { .name = nxt_string("share"), .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, .validator = nxt_conf_vldt_share, + }, { + .name = nxt_string("index"), + .type = NXT_CONF_VLDT_STRING, }, { .name = nxt_string("types"), .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, diff --git a/src/nxt_http.h b/src/nxt_http.h index 7cef134..9b819fb 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -209,6 +209,7 @@ typedef struct { nxt_str_t location; nxt_conf_value_t *proxy; nxt_conf_value_t *share; + nxt_conf_value_t *index; nxt_str_t chroot; nxt_conf_value_t *follow_symlinks; nxt_conf_value_t *traverse_mounts; diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 26f0662..c92f2cd 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -639,6 +639,11 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = { NXT_CONF_MAP_PTR, offsetof(nxt_http_action_conf_t, share) }, + { + nxt_string("index"), + NXT_CONF_MAP_PTR, + offsetof(nxt_http_action_conf_t, index) + }, { nxt_string("chroot"), NXT_CONF_MAP_STR, diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 663f896..b443a54 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -19,6 +19,7 @@ typedef struct { typedef struct { nxt_uint_t nshares; nxt_http_static_share_t *shares; + nxt_str_t index; #if (NXT_HAVE_OPENAT2) nxt_var_t *chroot; nxt_uint_t resolve; @@ -30,6 +31,7 @@ typedef struct { typedef struct { nxt_http_action_t *action; nxt_str_t share; + nxt_str_t index; #if (NXT_HAVE_OPENAT2) nxt_str_t chroot; #endif @@ -80,6 +82,8 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv; nxt_http_static_conf_t *conf; + static const nxt_str_t default_index = nxt_string("index.html"); + mp = tmcf->router_conf->mem_pool; conf = nxt_mp_zget(mp, sizeof(nxt_http_static_conf_t)); @@ -110,6 +114,13 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, conf->shares[i].is_const = nxt_var_is_const(var); } + if (acf->index == NULL) { + conf->index = default_index; + + } else { + nxt_conf_get_string(acf->index, &conf->index); + } + #if (NXT_HAVE_OPENAT2) if (acf->chroot.length > 0) { nxt_str_t chr, shr; @@ -222,8 +233,10 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #if (NXT_DEBUG) nxt_str_t shr; + nxt_str_t idx; nxt_var_raw(share->var, &shr); + idx = conf->index; #if (NXT_HAVE_OPENAT2) nxt_str_t chr; @@ -235,12 +248,15 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_str_set(&chr, ""); } - nxt_debug(task, "http static: \"%V\" (chroot: \"%V\")", &shr, &chr); + nxt_debug(task, "http static: \"%V\", index: \"%V\" (chroot: \"%V\")", + &shr, &idx, &chr); #else - nxt_debug(task, "http static: \"%V\"", &shr); + nxt_debug(task, "http static: \"%V\", index: \"%V\"", &shr, &idx); #endif #endif /* NXT_DEBUG */ + ctx->index = conf->index; + if (share->is_const) { nxt_var_raw(share->var, &ctx->share); @@ -282,7 +298,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) struct tm tm; nxt_buf_t *fb; nxt_int_t ret; - nxt_str_t *shr, exten, *mtype; + nxt_str_t *shr, *index, exten, *mtype; nxt_uint_t level; nxt_file_t *f, file; nxt_file_info_t fi; @@ -295,8 +311,6 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) nxt_http_static_ctx_t *ctx; nxt_http_static_conf_t *conf; - static const nxt_str_t index = nxt_string("index.html"); - r = obj; ctx = data; action = ctx->action; @@ -307,12 +321,12 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) mtype = NULL; shr = &ctx->share; + index = &ctx->index; if (shr->start[shr->length - 1] == '/') { - /* TODO: dynamic index setting. */ - nxt_str_set(&exten, ".html"); + nxt_http_static_extract_extension(index, &exten); - length = shr->length + index.length; + length = shr->length + index->length; fname = nxt_mp_nget(r->mem_pool, length + 1); if (nxt_slow_path(fname == NULL)) { @@ -321,7 +335,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) p = fname; p = nxt_cpymem(p, shr->start, shr->length); - p = nxt_cpymem(p, index.start, index.length); + p = nxt_cpymem(p, index->start, index->length); *p = '\0'; } else { diff --git a/test/test_static.py b/test/test_static.py index 76668a1..70ae676 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -14,7 +14,7 @@ class TestStatic(TestApplicationProto): def setup_method(self): os.makedirs(option.temp_dir + '/assets/dir') - with open(option.temp_dir + '/assets/index.html', 'w') as index, open( + with open(option.temp_dir + '/assets/index_.html', 'w') as index, open( option.temp_dir + '/assets/README', 'w' ) as readme, open( option.temp_dir + '/assets/log.log', 'w' @@ -32,7 +32,8 @@ class TestStatic(TestApplicationProto): "routes": [ { "action": { - "share": option.temp_dir + "/assets$uri" + "share": option.temp_dir + "/assets$uri", + "index": "index_.html" } } ], @@ -90,7 +91,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2' def test_static_index(self): - assert self.get(url='/index.html')['body'] == '0123456789', 'index' + assert self.get(url='/index_.html')['body'] == '0123456789', 'index' assert self.get(url='/')['body'] == '0123456789', 'index 2' assert self.get(url='//')['body'] == '0123456789', 'index 3' assert self.get(url='/.')['body'] == '0123456789', 'index 4' @@ -99,7 +100,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/#blah')['body'] == '0123456789', 'index anchor' assert self.get(url='/dir/')['status'] == 404, 'index not found' - resp = self.get(url='/index.html/') + resp = self.get(url='/index_.html/') assert resp['status'] == 404, 'index not found 2 status' assert ( resp['headers']['Content-Type'] == 'text/html' @@ -123,7 +124,7 @@ class TestStatic(TestApplicationProto): assert etag != etag_2, 'different ETag' assert etag == self.get(url='/')['headers']['ETag'], 'same ETag' - with open(temp_dir + '/assets/index.html', 'w') as f: + with open(temp_dir + '/assets/index_.html', 'w') as f: f.write('blah') assert etag != self.get(url='/')['headers']['ETag'], 'new ETag' @@ -262,7 +263,7 @@ class TestStatic(TestApplicationProto): == 'text/x-code/x-blah/x-blah' ), 'mime_types string case insensitive' assert ( - self.get(url='/index.html')['headers']['Content-Type'] + self.get(url='/index_.html')['headers']['Content-Type'] == 'text/plain' ), 'mime_types html' assert ( -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:27 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:27 +0100 Subject: [PATCH v3 09/12] Static: variables in the "index" option. In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-10-alx.manpages@gmail.com> This adds support for variables in the "index" option. An example: { "share": "/srv/www/data/static/$uri", "index": "$method.html" } When is requested, will be served. === test_static.py: Rename to , to be able to test this feature, and set "index": "$host.html>". I also tried this feature in my own computer, where I tried the following: - Setting "index" to "$method.html", and check that is being served. - Not setting index, and check that is being served. - Setting "index" to "$asdf", and check that the configuration fails: { "error": "Invalid configuration.", "detail": "Unknown variable \"asdf\" in the \"index\" value." } Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- docs/changes.xml | 6 ++++++ src/nxt_conf_validation.c | 1 + src/nxt_http_static.c | 29 +++++++++++++++++++++-------- test/test_static.py | 13 +++++++------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 07f3c83..8931165 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -18,6 +18,12 @@ date="" time="" packager="Andrei Belov <defan at nginx.com>"> + + +variables support in the "index" option. + + + new "index" option to specify a custom index file name. diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index bdc38b0..6236720 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -648,6 +648,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { }, { .name = nxt_string("index"), .type = NXT_CONF_VLDT_STRING, + .flags = NXT_CONF_VLDT_VAR, }, { .name = nxt_string("types"), .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 2a176d0..57d8ca8 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -19,7 +19,7 @@ typedef struct { typedef struct { nxt_uint_t nshares; nxt_http_static_share_t *shares; - nxt_str_t index; + nxt_var_t *index; #if (NXT_HAVE_OPENAT2) nxt_var_t *chroot; nxt_uint_t resolve; @@ -115,12 +115,19 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, } if (acf->index == NULL) { - conf->index = default_index; + str = default_index; } else { - nxt_conf_get_string(acf->index, &conf->index); + nxt_conf_get_string(acf->index, &str); } + var = nxt_var_compile(&str, mp, 1); + if (nxt_slow_path(var == NULL)) { + return NXT_ERROR; + } + + conf->index = var; + #if (NXT_HAVE_OPENAT2) if (acf->chroot.length > 0) { nxt_str_t chr, shr; @@ -226,7 +233,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; + nxt_bool_t shr_is_const, idx_is_const; conf = ctx->action->u.conf; @@ -237,7 +244,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_str_t idx; nxt_var_raw(share->var, &shr); - idx = conf->index; + nxt_var_raw(conf->index, &idx); #if (NXT_HAVE_OPENAT2) nxt_str_t chr; @@ -257,8 +264,9 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #endif /* NXT_DEBUG */ shr_is_const = share->is_const; + idx_is_const = nxt_var_is_const(conf->index); - if (!shr_is_const) { + if (!shr_is_const || !idx_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); @@ -266,7 +274,12 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, } } - ctx->index = conf->index; + if (idx_is_const) { + nxt_var_raw(conf->index, &ctx->index); + + } else { + nxt_var_query(task, r->var_query, conf->index, &ctx->index); + } if (shr_is_const) { nxt_var_raw(share->var, &ctx->share); @@ -287,7 +300,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #endif } - if (shr_is_const) { + if (shr_is_const && idx_is_const) { nxt_http_static_send_ready(task, r, ctx); } else { diff --git a/test/test_static.py b/test/test_static.py index 70ae676..2190901 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -14,7 +14,8 @@ class TestStatic(TestApplicationProto): def setup_method(self): os.makedirs(option.temp_dir + '/assets/dir') - with open(option.temp_dir + '/assets/index_.html', 'w') as index, open( + with open(option.temp_dir + '/assets/localhost.html', 'w' + ) as index, open( option.temp_dir + '/assets/README', 'w' ) as readme, open( option.temp_dir + '/assets/log.log', 'w' @@ -33,7 +34,7 @@ class TestStatic(TestApplicationProto): { "action": { "share": option.temp_dir + "/assets$uri", - "index": "index_.html" + "index": "$host.html" } } ], @@ -91,7 +92,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2' def test_static_index(self): - assert self.get(url='/index_.html')['body'] == '0123456789', 'index' + assert self.get(url='/localhost.html')['body'] == '0123456789', 'index' assert self.get(url='/')['body'] == '0123456789', 'index 2' assert self.get(url='//')['body'] == '0123456789', 'index 3' assert self.get(url='/.')['body'] == '0123456789', 'index 4' @@ -100,7 +101,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/#blah')['body'] == '0123456789', 'index anchor' assert self.get(url='/dir/')['status'] == 404, 'index not found' - resp = self.get(url='/index_.html/') + resp = self.get(url='/localhost.html/') assert resp['status'] == 404, 'index not found 2 status' assert ( resp['headers']['Content-Type'] == 'text/html' @@ -124,7 +125,7 @@ class TestStatic(TestApplicationProto): assert etag != etag_2, 'different ETag' assert etag == self.get(url='/')['headers']['ETag'], 'same ETag' - with open(temp_dir + '/assets/index_.html', 'w') as f: + with open(temp_dir + '/assets/localhost.html', 'w') as f: f.write('blah') assert etag != self.get(url='/')['headers']['ETag'], 'new ETag' @@ -263,7 +264,7 @@ class TestStatic(TestApplicationProto): == 'text/x-code/x-blah/x-blah' ), 'mime_types string case insensitive' assert ( - self.get(url='/index_.html')['headers']['Content-Type'] + self.get(url='/localhost.html')['headers']['Content-Type'] == 'text/plain' ), 'mime_types html' assert ( -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:29 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:29 +0100 Subject: [PATCH v3 11/12] nxt_http_static_init(): Simplify branching In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-12-alx.manpages@gmail.com> Add a bit of code to the special case of no "index", so that the normal case is not in a branch. This makes the normal flow more readable, by hiding details of special cases in branches, even if that means making the special case a bit more complex than it needs to be. 'else' distracts the mental parser of the reader of the code: it means it needs to branch in both cases. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_static.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 57d8ca8..16744f2 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -115,12 +115,16 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, } if (acf->index == NULL) { - str = default_index; + acf->index = nxt_conf_create_object(mp, 1); + if (nxt_slow_path(acf->index == NULL)) { + return NXT_ERROR; + } - } else { - nxt_conf_get_string(acf->index, &str); + nxt_conf_set_string_dup(acf->index, mp, &default_index); } + nxt_conf_get_string(acf->index, &str); + var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:26 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:26 +0100 Subject: [PATCH v3 08/12] nxt_http_static_iterate(): generalize code In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-9-alx.manpages@gmail.com> 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 Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- 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 From alx.manpages at gmail.com Sun Dec 19 01:30:28 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:28 +0100 Subject: [PATCH v3 10/12] nxt_conf_set_string_dup(): Use 'const' for read-only parameter In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-11-alx.manpages@gmail.com> That parameter is not being modified in the function. Make it 'const' to allow passing 'static const' variables. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_conf.c | 3 ++- src/nxt_conf.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 3f0cfa8..967c455 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -192,7 +192,8 @@ nxt_conf_set_string(nxt_conf_value_t *value, nxt_str_t *str) nxt_int_t -nxt_conf_set_string_dup(nxt_conf_value_t *value, nxt_mp_t *mp, nxt_str_t *str) +nxt_conf_set_string_dup(nxt_conf_value_t *value, nxt_mp_t *mp, + const nxt_str_t *str) { nxt_str_t tmp, *ptr; diff --git a/src/nxt_conf.h b/src/nxt_conf.h index 8b3565f..09f2175 100644 --- a/src/nxt_conf.h +++ b/src/nxt_conf.h @@ -115,7 +115,7 @@ nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt); NXT_EXPORT void nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str); NXT_EXPORT void nxt_conf_set_string(nxt_conf_value_t *value, nxt_str_t *str); NXT_EXPORT nxt_int_t nxt_conf_set_string_dup(nxt_conf_value_t *value, - nxt_mp_t *mp, nxt_str_t *str); + nxt_mp_t *mp, const nxt_str_t *str); NXT_EXPORT double nxt_conf_get_number(nxt_conf_value_t *value); NXT_EXPORT uint8_t nxt_conf_get_boolean(nxt_conf_value_t *value); -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:30:30 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Sun, 19 Dec 2021 02:30:30 +0100 Subject: [PATCH v3 12/12] Static: multiple paths in the "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211219013030.51372-13-alx.manpages@gmail.com> This adds support for multiple paths in the "index" option. An example: { "share": "/srv/www/stat/static/$uri", "index": [ "$method.html", "alt.html" ] } When is requested, will be served if it exists; otherwise, will be served. === test_static.py: Use an array instead of a string for "index". Add a nonexisting file name to the beginning of the array to make sure that the next file is being served. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- docs/changes.xml | 6 ++++++ src/nxt_conf_validation.c | 2 +- src/nxt_http_static.c | 31 ++++++++++++++++++++++--------- test/test_static.py | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 8931165..7b0f6a7 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -18,6 +18,12 @@ date="" time="" packager="Andrei Belov <defan at nginx.com>"> + + +multiple paths in the "index" option. + + + variables support in the "index" option. diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 6236720..ede5bf1 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -647,7 +647,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { .validator = nxt_conf_vldt_share, }, { .name = nxt_string("index"), - .type = NXT_CONF_VLDT_STRING, + .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, .flags = NXT_CONF_VLDT_VAR, }, { .name = nxt_string("types"), diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 16744f2..91bf26e 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -18,8 +18,9 @@ typedef struct { typedef struct { nxt_uint_t nshares; + nxt_uint_t nindices; nxt_http_static_share_t *shares; - nxt_var_t *index; + nxt_var_t **indices; #if (NXT_HAVE_OPENAT2) nxt_var_t *chroot; nxt_uint_t resolve; @@ -36,6 +37,7 @@ typedef struct { nxt_str_t chroot; #endif uint32_t share_idx; + uint32_t index_idx; uint8_t need_body; /* 1 bit */ } nxt_http_static_ctx_t; @@ -123,14 +125,23 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_conf_set_string_dup(acf->index, mp, &default_index); } - nxt_conf_get_string(acf->index, &str); - - var = nxt_var_compile(&str, mp, 1); - if (nxt_slow_path(var == NULL)) { + conf->nindices = nxt_conf_array_elements_count(acf->index); + conf->indices = nxt_mp_zget(mp, sizeof(*conf->indices) * conf->nindices); + if (nxt_slow_path(conf->indices == NULL)) { return NXT_ERROR; } - conf->index = var; + for (i = 0; i < conf->nindices; i++) { + cv = nxt_conf_get_array_element(acf->index, i); + nxt_conf_get_string(cv, &str); + + var = nxt_var_compile(&str, mp, 1); + if (nxt_slow_path(var == NULL)) { + return NXT_ERROR; + } + + conf->indices[i] = var; + } #if (NXT_HAVE_OPENAT2) if (acf->chroot.length > 0) { @@ -235,6 +246,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_http_static_ctx_t *ctx) { nxt_int_t ret; + nxt_var_t *index; nxt_http_static_conf_t *conf; nxt_http_static_share_t *share; nxt_bool_t shr_is_const, idx_is_const; @@ -242,6 +254,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, conf = ctx->action->u.conf; share = &conf->shares[ctx->share_idx]; + index = conf->indices[ctx->index_idx]; #if (NXT_DEBUG) nxt_str_t shr; @@ -268,7 +281,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #endif /* NXT_DEBUG */ shr_is_const = share->is_const; - idx_is_const = nxt_var_is_const(conf->index); + idx_is_const = nxt_var_is_const(index); if (!shr_is_const || !idx_is_const) { ret = nxt_var_query_init(&r->var_query, r, r->mem_pool); @@ -279,10 +292,10 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, } if (idx_is_const) { - nxt_var_raw(conf->index, &ctx->index); + nxt_var_raw(index, &ctx->index); } else { - nxt_var_query(task, r->var_query, conf->index, &ctx->index); + nxt_var_query(task, r->var_query, index, &ctx->index); } if (shr_is_const) { diff --git a/test/test_static.py b/test/test_static.py index 2190901..7fe40b6 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -34,7 +34,7 @@ class TestStatic(TestApplicationProto): { "action": { "share": option.temp_dir + "/assets$uri", - "index": "$host.html" + "index": ["idontexist", "$host.html"] } } ], -- 2.34.1 From alx.manpages at gmail.com Sun Dec 19 01:49:03 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Sun, 19 Dec 2021 02:49:03 +0100 Subject: [PATCH v3 12/12] Static: multiple paths in the "index" option In-Reply-To: <20211219013030.51372-13-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> <20211219013030.51372-13-alx.manpages@gmail.com> Message-ID: <98923d1b-a187-df01-dbe7-5e080f36905c@gmail.com> On 12/19/21 02:30, Alejandro Colomar wrote: > diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c > index 16744f2..91bf26e 100644 > --- a/src/nxt_http_static.c > +++ b/src/nxt_http_static.c > @@ -123,14 +125,23 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, > nxt_conf_set_string_dup(acf->index, mp, &default_index); > } > > - nxt_conf_get_string(acf->index, &str); > - > - var = nxt_var_compile(&str, mp, 1); > - if (nxt_slow_path(var == NULL)) { > + conf->nindices = nxt_conf_array_elements_count(acf->index); > + conf->indices = nxt_mp_zget(mp, sizeof(*conf->indices) * conf->nindices); BTW, I forgot to comment something here: I see that you always use 'p = xxallocxx(sizeof(type));' instead of 'p = xxallocxx(sizeof(*p));'. I find using the variable instead of it's type much more safe, since if you change the type of the variable and you forget to change every malloc call related to it, you have a new shiny bug, while with this code, it is updated automatically (of course a variable name change could produce a bug too, but normally renaming a variable will result in the code not compiling). I guess some compiler warning may be able to catch this, but I think it's safer to not use that construct at all. See also: What do you think about it? Thanks, Alex -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From vbart at nginx.com Sun Dec 19 03:11:50 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Sun, 19 Dec 2021 06:11:50 +0300 Subject: [PATCH v3 12/12] Static: multiple paths in the "index" option In-Reply-To: <20211219013030.51372-13-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> <20211219013030.51372-13-alx.manpages@gmail.com> Message-ID: <2115439.irdbgypaU6@vbart-laptop> On Sunday, 19 December 2021 04:30:30 MSK Alejandro Colomar wrote: [..] > @@ -242,6 +254,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, > conf = ctx->action->u.conf; > > share = &conf->shares[ctx->share_idx]; > + index = conf->indices[ctx->index_idx]; > > #if (NXT_DEBUG) > nxt_str_t shr; [..] I haven't applied and tested this patch yet, but are you sure that it works? Because from just a brief look I don't see where ctx->index_idx is incremented. Am I missing somehting? -- Valentin From alx.manpages at gmail.com Sun Dec 19 11:39:29 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Sun, 19 Dec 2021 12:39:29 +0100 Subject: [PATCH v3 12/12] Static: multiple paths in the "index" option In-Reply-To: <2115439.irdbgypaU6@vbart-laptop> References: <20211219013030.51372-1-alx.manpages@gmail.com> <20211219013030.51372-13-alx.manpages@gmail.com> <2115439.irdbgypaU6@vbart-laptop> Message-ID: <30689244-d586-9aae-ef15-52ae0d1619dd@gmail.com> Hi Valentin, On 12/19/21 04:11, Valentin V. Bartenev wrote: > On Sunday, 19 December 2021 04:30:30 MSK Alejandro Colomar wrote: > [..] >> @@ -242,6 +254,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, >> conf = ctx->action->u.conf; >> >> share = &conf->shares[ctx->share_idx]; >> + index = conf->indices[ctx->index_idx]; >> >> #if (NXT_DEBUG) >> nxt_str_t shr; > [..] > > I haven't applied and tested this patch yet, but are you sure that it works? > Because from just a brief look I don't see where ctx->index_idx is incremented. You're right. It doesn't work. Patch [12/12] is still a work in progress. I should have mentioned that in the commit message in this patch, instead of just mentioning it in the overview of the patch set. Instead, the commit message was misleading, since I wrote there what this commit should do when it's finished, instead of what it's doing right now. > Am I missing somehting? I explained it in the cover letter of this patch set revision: , which is patch [v3 00/12]: On 12/19/21 02:30, Alejandro Colomar wrote: > For this review of the patch set, I didn't yet do much testing. I > passed all previously existing pytests. The only one that fails > is the one I modified in patch 12 (the last one), which is to be > expected, since I didn't yet write code to iterate over the > indices (it's just picking the first element in the array always). > If you reverse the order in the array (in the pytest) to be > ["$host.html", "idontexist"] > it passes the test, which at least makes me happy since the > part that should still work (compared to step 2) still works. I assumed you were familiar with what git calls a cover letter. git-format-patch(1): --[no-]cover-letter In addition to the patches, generate a cover letter file containing the branch description, shortlog and the overall diffstat. You can fill in a description in the file before sending it out. Git numbers patches starting from 1, and then there's an optional patch 0, controlled by --cover-letter, which is the first email in the thread, and gives an overview of the patch set. Regards, Alex -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From vbart at nginx.com Sun Dec 19 15:22:01 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Sun, 19 Dec 2021 18:22:01 +0300 Subject: [PATCH v3 12/12] Static: multiple paths in the "index" option In-Reply-To: <30689244-d586-9aae-ef15-52ae0d1619dd@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> <2115439.irdbgypaU6@vbart-laptop> <30689244-d586-9aae-ef15-52ae0d1619dd@gmail.com> Message-ID: <5795517.lOV4Wx5bFT@vbart-laptop> On Sunday, 19 December 2021 14:39:29 MSK Alejandro Colomar (man-pages) wrote: > Hi Valentin, > > On 12/19/21 04:11, Valentin V. Bartenev wrote: > > On Sunday, 19 December 2021 04:30:30 MSK Alejandro Colomar wrote: > > [..] > >> @@ -242,6 +254,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, > >> conf = ctx->action->u.conf; > >> > >> share = &conf->shares[ctx->share_idx]; > >> + index = conf->indices[ctx->index_idx]; > >> > >> #if (NXT_DEBUG) > >> nxt_str_t shr; > > [..] > > > > I haven't applied and tested this patch yet, but are you sure that it works? > > Because from just a brief look I don't see where ctx->index_idx is incremented. > > You're right. It doesn't work. Patch [12/12] is still a work in > progress. I should have mentioned that in the commit message in this > patch, instead of just mentioning it in the overview of the patch set. > Instead, the commit message was misleading, since I wrote there what > this commit should do when it's finished, instead of what it's doing > right now. > > > Am I missing somehting? > > I explained it in the cover letter of this patch set revision: > , > which is patch [v3 00/12]: Oh.. ok, I've missed that letter at the first look. Will reply to it then. -- Valentin From vbart at nginx.com Sun Dec 19 15:47:48 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Sun, 19 Dec 2021 18:47:48 +0300 Subject: [PATCH v3 00/12] Static: Implement new "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <1897474.PYKUYFuaPT@vbart-laptop> On Sunday, 19 December 2021 04:30:18 MSK Alejandro Colomar wrote: > Hi Valentin, > > I have implemented part of the last step for adding this feature, > as you proposed them: > > *(1) Add new "index" option, with minimal support (a string). > *(2) Allow variables in the "index" option. > +(3) Allow multiple filenames in the "index" option. > > However, there's something that I couldn't yet fully understand, > which I need for this: how does the iteration of shares exactly > work, how do other variables (e.g., chroot, fallback) intervene, > and how is index expected to intervene in that mix. Since instead > of an explicit loop there are quite some nested function calls, > I couldn't manage to understand it. Could you please share some > brief description of the purpose of each static function in > 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. -- Valentin From scottvankalken at gmail.com Mon Dec 20 03:09:58 2021 From: scottvankalken at gmail.com (Scott van Kalken) Date: Mon, 20 Dec 2021 14:09:58 +1100 Subject: Odd question around config Message-ID: Hey all, I'm wondering if anyone knows whether or not unit will generate any sort of event on a configuration change. The reason I ask is that it would seem to be handy to have an event generated when a config is updated. I've been playing around with a peer to peer configuration sync between instances. Think of it this way: - Nodes boot up and join a mesh network - Nodes join a peer to peer pub sub message system (no central broker here as it's peer to peer) - I have a REST API endpoint that allows me to consume a message that is then sent to all nodes that are subscribed to the topic Presently, I can send a message saying "there is a config update" and all nodes that are subscribed to config updates will come and get the config from the node that published the message. It would be cool if there were an event generated that I could listen for though. It's a work in progress, and frankly at the moment is a bit experimental :), remember that it's peer to peer so at any point in time, any node can say "I have new config" and all other nodes will pull from the one that published the message. svk. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.coyle at live.ie Tue Dec 21 12:10:01 2021 From: kevin.coyle at live.ie (kevin coyle) Date: Tue, 21 Dec 2021 12:10:01 +0000 Subject: Kemo subcription Message-ID: My kemo iptv subcription Get Outlook for Android -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.coyle at live.ie Tue Dec 21 12:20:23 2021 From: kevin.coyle at live.ie (kevin coyle) Date: Tue, 21 Dec 2021 12:20:23 +0000 Subject: Kemo subcription In-Reply-To: References: Message-ID: Can you please send me further instructions on how to login to my account Get Outlook for Android ________________________________ From: unit on behalf of kevin coyle Sent: Tuesday, December 21, 2021 12:10:01 PM To: unit at nginx.org Subject: Kemo subcription My kemo iptv subcription Get Outlook for Android -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.coyle at live.ie Tue Dec 21 14:44:27 2021 From: kevin.coyle at live.ie (kevin coyle) Date: Tue, 21 Dec 2021 14:44:27 +0000 Subject: Kemo subcription In-Reply-To: References: Message-ID: Got it working ok,Thanks Get Outlook for Android ________________________________ From: unit on behalf of kevin coyle Sent: Tuesday, December 21, 2021 12:20:23 PM To: unit at nginx.org Subject: Re: Kemo subcription Can you please send me further instructions on how to login to my account Get Outlook for Android ________________________________ From: unit on behalf of kevin coyle Sent: Tuesday, December 21, 2021 12:10:01 PM To: unit at nginx.org Subject: Kemo subcription My kemo iptv subcription Get Outlook for Android -------------- next part -------------- An HTML attachment was scrubbed... URL: From alx.manpages at gmail.com Thu Dec 23 19:14:23 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Thu, 23 Dec 2021 20:14:23 +0100 Subject: [PATCH v3 00/12] Static: Implement new "index" option In-Reply-To: <1897474.PYKUYFuaPT@vbart-laptop> References: <20211219013030.51372-1-alx.manpages@gmail.com> <1897474.PYKUYFuaPT@vbart-laptop> Message-ID: Hi Valentin, On 12/19/21 16:47, Valentin V. Bartenev wrote: >> 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/ From alx.manpages at gmail.com Thu Dec 23 19:24:57 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:24:57 +0100 Subject: [PATCH v4 00/12] Static: Implement new "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-1-alx.manpages@gmail.com> Hi Valentin, I have implemented the last step for adding this feature, as you proposed them: *(1) Add new "index" option, with minimal support (a string). *(2) Allow variables in the "index" option. *(3) Allow multiple filenames in the "index" option. Plus some other changes that I needed for this to work (or even some that I just noticed while doing this and fixed too). v2: - Add support for variables in "index" - Don't move share_idx, since that caused unnecessary padding. - Use v3: - Don't use (as previously discussed). - Add a .gitignore: While doing this work, I had quite some accidents. This prevented them from happening again. I based it on the .gitignore of the Linux man-pages . - Treat non-arrays as arrays of size 1 (as discussed earlier today: ). - Simplify all of the code that can be simplified thanks to the change mentioned above (arrays of size 1). - Fix the indentation of some random lines that I found to have an incorrect indentation. - Reduce branching (especially 'else's), to improve readability. I didn't merge this change into the patch that adds the feature because there it adds too much complexity for nothing, and the patches read better separately. However, I patched it previous to the third step to simplify that patch too, so this change sits on a patch of its own better, I think. - Use const for a read-only parameter of a function. I didn't change other functions (not even in the same file), since that would mean a huuuge diff, and for consistency we would need to do it everywhere. So I only did it where I *needed* it to compile, for now. v4: - Actually iterate. This completes the feature. Alejandro Colomar (12): .gitignore: ignore new files nxt_conf.c: Treat non-arrays as arrays of size 1 Remove special cases for non-NXT_CONF_VALUE_ARRAY Fix indentation nxt_http_static_ctx_t: rename field 'index' to 'share_idx' test_static.py: formatting fix Static: add "index" option nxt_http_static_iterate(): generalize code Static: variables in the "index" option nxt_conf_set_string_dup(): Use 'const' for read-only parameter nxt_http_static_init(): Simplify branching Static: multiple paths in the "index" option .gitignore | 2 + docs/changes.xml | 18 ++++++ src/nxt_conf.c | 7 ++- src/nxt_conf.h | 2 +- src/nxt_conf_validation.c | 8 ++- src/nxt_gnutls.c | 4 +- src/nxt_http.h | 15 ++--- src/nxt_http_route.c | 54 +++------------- src/nxt_http_static.c | 127 +++++++++++++++++++++++++------------- src/nxt_main_process.c | 2 +- src/nxt_openssl.c | 24 ++----- src/nxt_router.c | 23 ++----- src/nxt_time_parse.c | 6 +- src/nxt_unit.c | 4 +- src/nxt_work_queue.h | 4 +- src/perl/nxt_perl_psgi.c | 2 +- src/python/nxt_python.c | 9 --- test/test_static.py | 18 ++++-- 18 files changed, 167 insertions(+), 162 deletions(-) create mode 100644 .gitignore -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:00 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:00 +0100 Subject: [PATCH v4 03/12] Remove special cases for non-NXT_CONF_VALUE_ARRAY In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-4-alx.manpages@gmail.com> The previous commit made the functions accepting NXT_CONF_VALUE_ARRAY more generic, so that now they can handle non-arrays correctly. Modify calling code to remove special cases for arrays and non-arrays, taking special care that the path for non arrays is logically equivalent to the previous special cased code. Use the now-generic array code only. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_route.c | 45 +++-------------------------------------- src/nxt_http_static.c | 28 ++++++------------------- src/nxt_openssl.c | 24 ++++++---------------- src/nxt_router.c | 23 ++++++--------------- src/python/nxt_python.c | 9 --------- 5 files changed, 21 insertions(+), 108 deletions(-) diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 606bf26..71ebf3f 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -718,13 +718,11 @@ nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp, { size_t size; uint32_t i, n; - nxt_bool_t array; nxt_conf_value_t *ruleset_cv; nxt_http_route_table_t *table; nxt_http_route_ruleset_t *ruleset; - array = (nxt_conf_type(table_cv) == NXT_CONF_ARRAY); - n = array ? nxt_conf_array_elements_count(table_cv) : 1; + n = nxt_conf_array_elements_count(table_cv); size = sizeof(nxt_http_route_table_t) + n * sizeof(nxt_http_route_ruleset_t *); @@ -736,18 +734,6 @@ nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp, table->items = n; table->object = NXT_HTTP_ROUTE_TABLE; - if (!array) { - ruleset = nxt_http_route_ruleset_create(task, mp, table_cv, object, - case_sensitive, encoding); - if (nxt_slow_path(ruleset == NULL)) { - return NULL; - } - - table->ruleset[0] = ruleset; - - return table; - } - for (i = 0; i < n; i++) { ruleset_cv = nxt_conf_get_array_element(table_cv, i); @@ -911,13 +897,11 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp, size_t size; uint32_t i, n; nxt_int_t ret; - nxt_bool_t string; nxt_conf_value_t *value; nxt_http_route_rule_t *rule; nxt_http_route_pattern_t *pattern; - string = (nxt_conf_type(cv) != NXT_CONF_ARRAY); - n = string ? 1 : nxt_conf_array_elements_count(cv); + n = nxt_conf_array_elements_count(cv); size = sizeof(nxt_http_route_rule_t) + n * sizeof(nxt_http_route_pattern_t); rule = nxt_mp_alloc(mp, size); @@ -929,17 +913,6 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp, pattern = &rule->pattern[0]; - if (string) { - pattern[0].case_sensitive = case_sensitive; - ret = nxt_http_route_pattern_create(task, mp, cv, &pattern[0], - pattern_case, encoding); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - return rule; - } - nxt_conf_array_qsort(cv, nxt_http_pattern_compare); for (i = 0; i < n; i++) { @@ -963,13 +936,11 @@ nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp, { size_t size; uint32_t i, n; - nxt_bool_t array; nxt_conf_value_t *value; nxt_http_route_addr_rule_t *addr_rule; nxt_http_route_addr_pattern_t *pattern; - array = (nxt_conf_type(cv) == NXT_CONF_ARRAY); - n = array ? nxt_conf_array_elements_count(cv) : 1; + n = nxt_conf_array_elements_count(cv); size = sizeof(nxt_http_route_addr_rule_t) + n * sizeof(nxt_http_route_addr_pattern_t); @@ -981,16 +952,6 @@ nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp, addr_rule->items = n; - if (!array) { - pattern = &addr_rule->addr_pattern[0]; - - if (nxt_http_route_addr_pattern_parse(mp, pattern, cv) != NXT_OK) { - return NULL; - } - - return addr_rule; - } - for (i = 0; i < n; i++) { pattern = &addr_rule->addr_pattern[i]; value = nxt_conf_get_array_element(cv, i); diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 36c1ebc..6b7cee7 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -77,7 +77,6 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_mp_t *mp; nxt_str_t str; nxt_var_t *var; - nxt_bool_t array; nxt_conf_value_t *cv; nxt_http_static_conf_t *conf; @@ -91,39 +90,24 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, action->handler = nxt_http_static; action->u.conf = conf; - array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY); - conf->nshares = array ? nxt_conf_array_elements_count(acf->share) : 1; - + conf->nshares = nxt_conf_array_elements_count(acf->share); conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t) * conf->nshares); if (nxt_slow_path(conf->shares == NULL)) { return NXT_ERROR; } - if (array) { - for (i = 0; i < conf->nshares; i++) { - cv = nxt_conf_get_array_element(acf->share, i); - nxt_conf_get_string(cv, &str); - - var = nxt_var_compile(&str, mp, 1); - if (nxt_slow_path(var == NULL)) { - return NXT_ERROR; - } - - conf->shares[i].var = var; - conf->shares[i].is_const = nxt_var_is_const(var); - } - - } else { - nxt_conf_get_string(acf->share, &str); + for (i = 0; i < conf->nshares; i++) { + cv = nxt_conf_get_array_element(acf->share, i); + nxt_conf_get_string(cv, &str); var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; } - conf->shares[0].var = var; - conf->shares[0].is_const = nxt_var_is_const(var); + conf->shares[i].var = var; + conf->shares[i].is_const = nxt_var_is_const(var); } #if (NXT_HAVE_OPENAT2) diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c index 1e08015..a4564f1 100644 --- a/src/nxt_openssl.c +++ b/src/nxt_openssl.c @@ -644,16 +644,10 @@ nxt_tls_ticket_keys(nxt_task_t *task, SSL_CTX *ctx, nxt_tls_init_t *tls_init, return NXT_OK; } - if (nxt_conf_type(tickets_conf) == NXT_CONF_ARRAY) { - count = nxt_conf_array_elements_count(tickets_conf); + count = nxt_conf_array_elements_count(tickets_conf); - if (count == 0) { - goto no_ticket; - } - - } else { - /* nxt_conf_type(tickets_conf) == NXT_CONF_STRING */ - count = 1; + if (count == 0) { + goto no_ticket; } #ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB @@ -673,15 +667,9 @@ nxt_tls_ticket_keys(nxt_task_t *task, SSL_CTX *ctx, nxt_tls_init_t *tls_init, i++; - if (nxt_conf_type(tickets_conf) == NXT_CONF_ARRAY) { - member = nxt_conf_get_array_element(tickets_conf, count - i); - if (member == NULL) { - break; - } - - } else { - /* nxt_conf_type(tickets_conf) == NXT_CONF_STRING */ - member = tickets_conf; + member = nxt_conf_get_array_element(tickets_conf, count - i); + if (member == NULL) { + break; } nxt_conf_get_string(member, &value); diff --git a/src/nxt_router.c b/src/nxt_router.c index 52ea0f3..b8ee0c7 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1924,25 +1924,14 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, tls_init->tickets_conf = nxt_conf_get_path(listener, &conf_tickets); - if (nxt_conf_type(certificate) == NXT_CONF_ARRAY) { - n = nxt_conf_array_elements_count(certificate); - - for (i = 0; i < n; i++) { - value = nxt_conf_get_array_element(certificate, i); - - nxt_assert(value != NULL); + n = nxt_conf_array_elements_count(certificate); + for (i = 0; i < n; i++) { + value = nxt_conf_get_array_element(certificate, i); - ret = nxt_router_conf_tls_insert(tmcf, value, skcf, - tls_init, i == 0); - if (nxt_slow_path(ret != NXT_OK)) { - goto fail; - } - } + nxt_assert(value != NULL); - } else { - /* NXT_CONF_STRING */ - ret = nxt_router_conf_tls_insert(tmcf, certificate, skcf, - tls_init, 1); + ret = nxt_router_conf_tls_insert(tmcf, value, skcf, + tls_init, i == 0); if (nxt_slow_path(ret != NXT_OK)) { goto fail; } diff --git a/src/python/nxt_python.c b/src/python/nxt_python.c index 8687c86..3edaa08 100644 --- a/src/python/nxt_python.c +++ b/src/python/nxt_python.c @@ -411,14 +411,7 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value) /* sys is a Borrowed reference. */ - if (nxt_conf_type(value) == NXT_CONF_STRING) { - n = 0; - goto value_is_string; - } - - /* NXT_CONF_ARRAY */ array = value; - n = nxt_conf_array_elements_count(array); while (n != 0) { @@ -432,8 +425,6 @@ nxt_python_set_path(nxt_task_t *task, nxt_conf_value_t *value) value = nxt_conf_get_array_element(array, n); - value_is_string: - nxt_conf_get_string(value, &str); path = PyString_FromStringAndSize((char *) str.start, str.length); -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:01 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:01 +0100 Subject: [PATCH v4 04/12] Fix indentation In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-5-alx.manpages@gmail.com> Some lines (incorrectly) had an indenteation of 5 or 9 spaces instead of 4 or 8. Fix them. Found with: $ ## 5 spaces instead of 4: $ $ find src/ -type f \ |grep -n '^ [^ *]'; $ ## 9 spaces instead of 8: $ $ find src/ -type f \ |grep -l '^ [^ *]' \ |xargs grep -L '^ [^ *].*)$' \ |xargs grep -n '^ [^ *]' Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_conf_validation.c | 4 ++-- src/nxt_gnutls.c | 4 ++-- src/nxt_http.h | 14 +++++++------- src/nxt_http_route.c | 4 ++-- src/nxt_main_process.c | 2 +- src/nxt_time_parse.c | 6 +++--- src/nxt_unit.c | 4 ++-- src/nxt_work_queue.h | 4 ++-- src/perl/nxt_perl_psgi.c | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 3f068bb..7edd638 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -114,7 +114,7 @@ static nxt_int_t nxt_conf_vldt_pass(nxt_conf_validation_t *vldt, static nxt_int_t nxt_conf_vldt_return(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_share(nxt_conf_validation_t *vldt, - nxt_conf_value_t *value, void *data); + nxt_conf_value_t *value, void *data); static nxt_int_t nxt_conf_vldt_share_element(nxt_conf_validation_t *vldt, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_proxy(nxt_conf_validation_t *vldt, @@ -194,7 +194,7 @@ static nxt_int_t nxt_conf_vldt_java_classpath(nxt_conf_validation_t *vldt, static nxt_int_t nxt_conf_vldt_java_option(nxt_conf_validation_t *vldt, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_upstream(nxt_conf_validation_t *vldt, - nxt_str_t *name, nxt_conf_value_t *value); + nxt_str_t *name, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_server(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_server_weight(nxt_conf_validation_t *vldt, diff --git a/src/nxt_gnutls.c b/src/nxt_gnutls.c index 4618dce..aab4699 100644 --- a/src/nxt_gnutls.c +++ b/src/nxt_gnutls.c @@ -708,11 +708,11 @@ nxt_gnutls_log_error_level(nxt_event_conn_t *c, ssize_t err) case GNUTLS_E_UNKNOWN_CIPHER_SUITE: /* -21 */ - /* Disable gnutls_bye(), because it returns GNUTLS_E_INTERNAL_ERROR. */ + /* Disable gnutls_bye(), because it returns GNUTLS_E_INTERNAL_ERROR. */ ssltls = c->u.ssltls; ssltls->no_shutdown = 1; - /* Fall through. */ + /* Fall through. */ case GNUTLS_E_UNEXPECTED_PACKET_LENGTH: /* -9 */ c->socket.error = 1000; /* Nonexistent errno code. */ diff --git a/src/nxt_http.h b/src/nxt_http.h index 02d66f5..7cef134 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -90,17 +90,17 @@ typedef union { #define nxt_http_field_name_set(_field, _name) \ do { \ - (_field)->name_length = nxt_length(_name); \ - (_field)->name = (u_char *) _name; \ + (_field)->name_length = nxt_length(_name); \ + (_field)->name = (u_char *) _name; \ } while (0) #define nxt_http_field_set(_field, _name, _value) \ do { \ - (_field)->name_length = nxt_length(_name); \ - (_field)->value_length = nxt_length(_value); \ - (_field)->name = (u_char *) _name; \ - (_field)->value = (u_char *) _value; \ + (_field)->name_length = nxt_length(_name); \ + (_field)->value_length = nxt_length(_value); \ + (_field)->name = (u_char *) _name; \ + (_field)->value = (u_char *) _value; \ } while (0) @@ -238,7 +238,7 @@ typedef struct { void (*body_read)(nxt_task_t *task, nxt_http_request_t *r); void (*local_addr)(nxt_task_t *task, nxt_http_request_t *r); void (*header_send)(nxt_task_t *task, nxt_http_request_t *r, - nxt_work_handler_t body_handler, void *data); + nxt_work_handler_t body_handler, void *data); void (*send)(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out); nxt_off_t (*body_bytes_sent)(nxt_task_t *task, nxt_http_proto_t proto); void (*discard)(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *last); diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 71ebf3f..26f0662 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -932,7 +932,7 @@ nxt_http_route_rule_create(nxt_task_t *task, nxt_mp_t *mp, nxt_http_route_addr_rule_t * nxt_http_route_addr_rule_create(nxt_task_t *task, nxt_mp_t *mp, - nxt_conf_value_t *cv) + nxt_conf_value_t *cv) { size_t size; uint32_t i, n; @@ -2294,7 +2294,7 @@ nxt_http_route_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end) name = NULL; start = p + 1; - } + } } if (name != NULL) { diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 9883f04..03761a1 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -579,7 +579,7 @@ nxt_main_process_created_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) -1, msg->port_msg.stream, 0, NULL); return; } - } + } #endif diff --git a/src/nxt_time_parse.c b/src/nxt_time_parse.c index 5a32b21..94c4328 100644 --- a/src/nxt_time_parse.c +++ b/src/nxt_time_parse.c @@ -282,9 +282,9 @@ nxt_time_parse(const u_char *p, size_t len) days = days - 719527 + 31 + 28; s = (uint64_t) days * 86400 - + (nxt_uint_t) hour * 3600 - + (nxt_uint_t) min * 60 - + (nxt_uint_t) sec; + + (nxt_uint_t) hour * 3600 + + (nxt_uint_t) min * 60 + + (nxt_uint_t) sec; #if (NXT_TIME_T_SIZE <= 4) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index dac612b..32bb07a 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -5114,9 +5114,9 @@ nxt_unit_ctx_alloc(nxt_unit_ctx_t *ctx, void *data) rc = nxt_unit_ctx_init(lib, new_ctx, data); if (nxt_slow_path(rc != NXT_UNIT_OK)) { - nxt_unit_free(ctx, new_ctx); + nxt_unit_free(ctx, new_ctx); - return NULL; + return NULL; } queue_fd = -1; diff --git a/src/nxt_work_queue.h b/src/nxt_work_queue.h index 6c2d6c2..ffa21d2 100644 --- a/src/nxt_work_queue.h +++ b/src/nxt_work_queue.h @@ -16,12 +16,12 @@ struct nxt_task_s { uint32_t ident; nxt_work_t *next_work; - /* TODO: exception_handler, prev/next task, subtasks. */ + /* TODO: exception_handler, prev/next task, subtasks. */ }; #define nxt_task_next_ident() \ - ((uint32_t) nxt_atomic_fetch_add(&nxt_task_ident, 1) & 0x3FFFFFFF) + ((uint32_t) nxt_atomic_fetch_add(&nxt_task_ident, 1) & 0x3FFFFFFF) /* diff --git a/src/perl/nxt_perl_psgi.c b/src/perl/nxt_perl_psgi.c index 02555c9..e40cb5d 100644 --- a/src/perl/nxt_perl_psgi.c +++ b/src/perl/nxt_perl_psgi.c @@ -640,7 +640,7 @@ nxt_perl_psgi_env_create(PerlInterpreter *my_perl, do { \ if (nxt_slow_path((FNS) != NXT_UNIT_OK)) \ goto fail; \ - } while (0) + } while (0) #define NL(S) (S), sizeof(S)-1 -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:03 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:03 +0100 Subject: [PATCH v4 06/12] test_static.py: formatting fix In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-7-alx.manpages@gmail.com> Expand indentation, to allow for the addition of an "index" configuration. This only changes whitespace/indentation. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- test/test_static.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_static.py b/test/test_static.py index 80f4c61..76668a1 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -30,7 +30,11 @@ class TestStatic(TestApplicationProto): { "listeners": {"*:7080": {"pass": "routes"}}, "routes": [ - {"action": {"share": option.temp_dir + "/assets$uri"}} + { + "action": { + "share": option.temp_dir + "/assets$uri" + } + } ], "settings": { "http": { -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:04 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:04 +0100 Subject: [PATCH v4 07/12] Static: add "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-8-alx.manpages@gmail.com> This supports a new option "index", that configures a custom index file name that will be served when a directory is requested. This initial support only allows a single fixed string. An example: { "share": "/www/data/static/$uri", "index": "lookatthis.htm" } When is requested, will be served. If the option is missing, default to "index.html". === nxt_conf_validator.c: Accept "index" as a member of "share", and make sure it is a string. === test_static.py: Rename to , to be able to test this new option, and set "index": "index_.html". Perhaps we should also add a test to check that if "index" is omitted, the default "index.html" is used. I also tried this feature in my own computer, where I tried the following: - Setting "index" to "lookatthis.htm", and check that the correct file is being served (check both a different name and a different extension). - Not setting "index", and check that is being served. - Settind "index" to an array of strings, and check that the configuration fails: { "error": "Invalid configuration.", "detail": "The \"index\" value must be a string, but not an array." } Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- docs/changes.xml | 6 ++++++ src/nxt_conf_validation.c | 3 +++ src/nxt_http.h | 1 + src/nxt_http_route.c | 5 +++++ src/nxt_http_static.c | 32 +++++++++++++++++++++++--------- test/test_static.py | 13 +++++++------ 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 8890e4d..07f3c83 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -18,6 +18,12 @@ date="" time="" packager="Andrei Belov <defan at nginx.com>"> + + +new "index" option to specify a custom index file name. + + + NGINX Unit updated to 1.27.0. diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 7edd638..bdc38b0 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -645,6 +645,9 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { .name = nxt_string("share"), .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, .validator = nxt_conf_vldt_share, + }, { + .name = nxt_string("index"), + .type = NXT_CONF_VLDT_STRING, }, { .name = nxt_string("types"), .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, diff --git a/src/nxt_http.h b/src/nxt_http.h index 7cef134..9b819fb 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -209,6 +209,7 @@ typedef struct { nxt_str_t location; nxt_conf_value_t *proxy; nxt_conf_value_t *share; + nxt_conf_value_t *index; nxt_str_t chroot; nxt_conf_value_t *follow_symlinks; nxt_conf_value_t *traverse_mounts; diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 26f0662..c92f2cd 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -639,6 +639,11 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = { NXT_CONF_MAP_PTR, offsetof(nxt_http_action_conf_t, share) }, + { + nxt_string("index"), + NXT_CONF_MAP_PTR, + offsetof(nxt_http_action_conf_t, index) + }, { nxt_string("chroot"), NXT_CONF_MAP_STR, diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 663f896..b443a54 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -19,6 +19,7 @@ typedef struct { typedef struct { nxt_uint_t nshares; nxt_http_static_share_t *shares; + nxt_str_t index; #if (NXT_HAVE_OPENAT2) nxt_var_t *chroot; nxt_uint_t resolve; @@ -30,6 +31,7 @@ typedef struct { typedef struct { nxt_http_action_t *action; nxt_str_t share; + nxt_str_t index; #if (NXT_HAVE_OPENAT2) nxt_str_t chroot; #endif @@ -80,6 +82,8 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv; nxt_http_static_conf_t *conf; + static const nxt_str_t default_index = nxt_string("index.html"); + mp = tmcf->router_conf->mem_pool; conf = nxt_mp_zget(mp, sizeof(nxt_http_static_conf_t)); @@ -110,6 +114,13 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, conf->shares[i].is_const = nxt_var_is_const(var); } + if (acf->index == NULL) { + conf->index = default_index; + + } else { + nxt_conf_get_string(acf->index, &conf->index); + } + #if (NXT_HAVE_OPENAT2) if (acf->chroot.length > 0) { nxt_str_t chr, shr; @@ -222,8 +233,10 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #if (NXT_DEBUG) nxt_str_t shr; + nxt_str_t idx; nxt_var_raw(share->var, &shr); + idx = conf->index; #if (NXT_HAVE_OPENAT2) nxt_str_t chr; @@ -235,12 +248,15 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_str_set(&chr, ""); } - nxt_debug(task, "http static: \"%V\" (chroot: \"%V\")", &shr, &chr); + nxt_debug(task, "http static: \"%V\", index: \"%V\" (chroot: \"%V\")", + &shr, &idx, &chr); #else - nxt_debug(task, "http static: \"%V\"", &shr); + nxt_debug(task, "http static: \"%V\", index: \"%V\"", &shr, &idx); #endif #endif /* NXT_DEBUG */ + ctx->index = conf->index; + if (share->is_const) { nxt_var_raw(share->var, &ctx->share); @@ -282,7 +298,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) struct tm tm; nxt_buf_t *fb; nxt_int_t ret; - nxt_str_t *shr, exten, *mtype; + nxt_str_t *shr, *index, exten, *mtype; nxt_uint_t level; nxt_file_t *f, file; nxt_file_info_t fi; @@ -295,8 +311,6 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) nxt_http_static_ctx_t *ctx; nxt_http_static_conf_t *conf; - static const nxt_str_t index = nxt_string("index.html"); - r = obj; ctx = data; action = ctx->action; @@ -307,12 +321,12 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) mtype = NULL; shr = &ctx->share; + index = &ctx->index; if (shr->start[shr->length - 1] == '/') { - /* TODO: dynamic index setting. */ - nxt_str_set(&exten, ".html"); + nxt_http_static_extract_extension(index, &exten); - length = shr->length + index.length; + length = shr->length + index->length; fname = nxt_mp_nget(r->mem_pool, length + 1); if (nxt_slow_path(fname == NULL)) { @@ -321,7 +335,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) p = fname; p = nxt_cpymem(p, shr->start, shr->length); - p = nxt_cpymem(p, index.start, index.length); + p = nxt_cpymem(p, index->start, index->length); *p = '\0'; } else { diff --git a/test/test_static.py b/test/test_static.py index 76668a1..70ae676 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -14,7 +14,7 @@ class TestStatic(TestApplicationProto): def setup_method(self): os.makedirs(option.temp_dir + '/assets/dir') - with open(option.temp_dir + '/assets/index.html', 'w') as index, open( + with open(option.temp_dir + '/assets/index_.html', 'w') as index, open( option.temp_dir + '/assets/README', 'w' ) as readme, open( option.temp_dir + '/assets/log.log', 'w' @@ -32,7 +32,8 @@ class TestStatic(TestApplicationProto): "routes": [ { "action": { - "share": option.temp_dir + "/assets$uri" + "share": option.temp_dir + "/assets$uri", + "index": "index_.html" } } ], @@ -90,7 +91,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2' def test_static_index(self): - assert self.get(url='/index.html')['body'] == '0123456789', 'index' + assert self.get(url='/index_.html')['body'] == '0123456789', 'index' assert self.get(url='/')['body'] == '0123456789', 'index 2' assert self.get(url='//')['body'] == '0123456789', 'index 3' assert self.get(url='/.')['body'] == '0123456789', 'index 4' @@ -99,7 +100,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/#blah')['body'] == '0123456789', 'index anchor' assert self.get(url='/dir/')['status'] == 404, 'index not found' - resp = self.get(url='/index.html/') + resp = self.get(url='/index_.html/') assert resp['status'] == 404, 'index not found 2 status' assert ( resp['headers']['Content-Type'] == 'text/html' @@ -123,7 +124,7 @@ class TestStatic(TestApplicationProto): assert etag != etag_2, 'different ETag' assert etag == self.get(url='/')['headers']['ETag'], 'same ETag' - with open(temp_dir + '/assets/index.html', 'w') as f: + with open(temp_dir + '/assets/index_.html', 'w') as f: f.write('blah') assert etag != self.get(url='/')['headers']['ETag'], 'new ETag' @@ -262,7 +263,7 @@ class TestStatic(TestApplicationProto): == 'text/x-code/x-blah/x-blah' ), 'mime_types string case insensitive' assert ( - self.get(url='/index.html')['headers']['Content-Type'] + self.get(url='/index_.html')['headers']['Content-Type'] == 'text/plain' ), 'mime_types html' assert ( -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:24:58 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:24:58 +0100 Subject: [PATCH v4 01/12] .gitignore: ignore new files In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-2-alx.manpages@gmail.com> When working with git, one has to be very careful of not adding temporary files resulting from compilation, testing, or text editors. With this .gitignore, one can add all of the changes with `git add .` without having to specify the files manually, avoiding accidents. When a new file is created and should really be added, one can add it still with the '-f' option to git-add(1). Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ed833f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore everything new by default +/* -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:24:59 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:24:59 +0100 Subject: [PATCH v4 02/12] nxt_conf.c: Treat non-arrays as arrays of size 1 In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-3-alx.manpages@gmail.com> Similar to how C pointers to variables can always be considered as pointers to the first element of an array of size 1 (see the following code for an example of how they are equivalent), treating non-NXT_CONF_VALUE_ARRAY as if they were NXT_CONF_VALUE_ARRAYs of size 1 allows for simpler and more generic code. void foo(ptrdiff_t sz, int arr[sz]) { for (ptrdiff_t i = 0; i < sz; i++) arr[i] = 0; } void bar(void) { int x; int y[1]; foo(1, &x); foo(1, y); } nxt_conf_array_elements_count(): Return a size of 1 when input is non-array, instead of causing undefined behavior. That value (1) makes sense because it will be used as the limiter of a loop that loops over the array and calls nxt_conf_get_array_element(), which will return a correct element for such loops. nxt_conf_get_array_element(): Return the input pointer unmodified (i.e., a pointer to the unique element of a hypothetical array), instead of returning NULL, which wasn't very useful. nxt_conf_array_qsort(): Since it's a no-op for non-arrays, this doesn't need to be modified. Example of (correct) usage: void baz(nxt_conf_value_t *x) { /* 'x' may or may not be a NXT_CONF_VALUE_ARRAY */ ptrdiff_t n; nxt_conf_value_t *elem; n = nxt_conf_array_elements_count(x); for (ptrdiff_t i = 0; i < n; i++) { elem = nxt_conf_get_array_element(x, i); /* do some work with 'elem' */ } } Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 1aca0a7..3f0cfa8 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -387,7 +387,7 @@ nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp, nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value) { - return value->u.array->count; + return (value->type == NXT_CONF_VALUE_ARRAY) ? value->u.array->count : 1; } @@ -736,7 +736,7 @@ nxt_conf_get_array_element(nxt_conf_value_t *value, uint32_t index) nxt_conf_array_t *array; if (value->type != NXT_CONF_VALUE_ARRAY) { - return NULL; + return (index == 0) ? value : NULL; } array = value->u.array; -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:07 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:07 +0100 Subject: [PATCH v4 10/12] nxt_conf_set_string_dup(): Use 'const' for read-only parameter In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-11-alx.manpages@gmail.com> That parameter is not being modified in the function. Make it 'const' to allow passing 'static const' variables. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_conf.c | 3 ++- src/nxt_conf.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 3f0cfa8..967c455 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -192,7 +192,8 @@ nxt_conf_set_string(nxt_conf_value_t *value, nxt_str_t *str) nxt_int_t -nxt_conf_set_string_dup(nxt_conf_value_t *value, nxt_mp_t *mp, nxt_str_t *str) +nxt_conf_set_string_dup(nxt_conf_value_t *value, nxt_mp_t *mp, + const nxt_str_t *str) { nxt_str_t tmp, *ptr; diff --git a/src/nxt_conf.h b/src/nxt_conf.h index 8b3565f..09f2175 100644 --- a/src/nxt_conf.h +++ b/src/nxt_conf.h @@ -115,7 +115,7 @@ nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt); NXT_EXPORT void nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str); NXT_EXPORT void nxt_conf_set_string(nxt_conf_value_t *value, nxt_str_t *str); NXT_EXPORT nxt_int_t nxt_conf_set_string_dup(nxt_conf_value_t *value, - nxt_mp_t *mp, nxt_str_t *str); + nxt_mp_t *mp, const nxt_str_t *str); NXT_EXPORT double nxt_conf_get_number(nxt_conf_value_t *value); NXT_EXPORT uint8_t nxt_conf_get_boolean(nxt_conf_value_t *value); -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:08 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:08 +0100 Subject: [PATCH v4 11/12] nxt_http_static_init(): Simplify branching In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-12-alx.manpages@gmail.com> Add a bit of code to the special case of no "index", so that the normal case is not in a branch. This makes the normal flow more readable, by hiding details of special cases in branches, even if that means making the special case a bit more complex than it needs to be. 'else' distracts the mental parser of the reader of the code: it means it needs to branch in both cases. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_static.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 57d8ca8..16744f2 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -115,12 +115,16 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, } if (acf->index == NULL) { - str = default_index; + acf->index = nxt_conf_create_object(mp, 1); + if (nxt_slow_path(acf->index == NULL)) { + return NXT_ERROR; + } - } else { - nxt_conf_get_string(acf->index, &str); + nxt_conf_set_string_dup(acf->index, mp, &default_index); } + nxt_conf_get_string(acf->index, &str); + var = nxt_var_compile(&str, mp, 1); if (nxt_slow_path(var == NULL)) { return NXT_ERROR; -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:09 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:09 +0100 Subject: [PATCH v4 12/12] Static: multiple paths in the "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-13-alx.manpages@gmail.com> This adds support for multiple paths in the "index" option. An example: { "share": "/srv/www/stat/static/$uri", "index": [ "$method.html", "alt.html" ] } When is requested, will be served if it exists; otherwise, will be served. === test_static.py: Use an array instead of a string for "index". Add a nonexisting file name to the beginning of the array to make sure that the next file is being served. I also tried this feature in my own computer, where I tried the following: - Setting "index" to ["idontexist", "$host.html"], and check that is being served. - Not setting "index", and check that is being served. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- docs/changes.xml | 6 ++++++ src/nxt_conf_validation.c | 2 +- src/nxt_http_static.c | 36 ++++++++++++++++++++++++++---------- test/test_static.py | 2 +- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 8931165..7b0f6a7 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -18,6 +18,12 @@ date="" time="" packager="Andrei Belov <defan at nginx.com>"> + + +multiple paths in the "index" option. + + + variables support in the "index" option. diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 6236720..ede5bf1 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -647,7 +647,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { .validator = nxt_conf_vldt_share, }, { .name = nxt_string("index"), - .type = NXT_CONF_VLDT_STRING, + .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, .flags = NXT_CONF_VLDT_VAR, }, { .name = nxt_string("types"), diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 16744f2..30b7fd6 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -18,8 +18,9 @@ typedef struct { typedef struct { nxt_uint_t nshares; + nxt_uint_t nindices; nxt_http_static_share_t *shares; - nxt_var_t *index; + nxt_var_t **indices; #if (NXT_HAVE_OPENAT2) nxt_var_t *chroot; nxt_uint_t resolve; @@ -36,6 +37,7 @@ typedef struct { nxt_str_t chroot; #endif uint32_t share_idx; + uint32_t index_idx; uint8_t need_body; /* 1 bit */ } nxt_http_static_ctx_t; @@ -123,14 +125,23 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_conf_set_string_dup(acf->index, mp, &default_index); } - nxt_conf_get_string(acf->index, &str); - - var = nxt_var_compile(&str, mp, 1); - if (nxt_slow_path(var == NULL)) { + conf->nindices = nxt_conf_array_elements_count(acf->index); + conf->indices = nxt_mp_zget(mp, sizeof(*conf->indices) * conf->nindices); + if (nxt_slow_path(conf->indices == NULL)) { return NXT_ERROR; } - conf->index = var; + for (i = 0; i < conf->nindices; i++) { + cv = nxt_conf_get_array_element(acf->index, i); + nxt_conf_get_string(cv, &str); + + var = nxt_var_compile(&str, mp, 1); + if (nxt_slow_path(var == NULL)) { + return NXT_ERROR; + } + + conf->indices[i] = var; + } #if (NXT_HAVE_OPENAT2) if (acf->chroot.length > 0) { @@ -235,6 +246,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_http_static_ctx_t *ctx) { nxt_int_t ret; + nxt_var_t *index; nxt_http_static_conf_t *conf; nxt_http_static_share_t *share; nxt_bool_t shr_is_const, idx_is_const; @@ -242,6 +254,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, conf = ctx->action->u.conf; share = &conf->shares[ctx->share_idx]; + index = conf->indices[ctx->index_idx]; #if (NXT_DEBUG) nxt_str_t shr; @@ -268,7 +281,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #endif /* NXT_DEBUG */ shr_is_const = share->is_const; - idx_is_const = nxt_var_is_const(conf->index); + idx_is_const = nxt_var_is_const(index); if (!shr_is_const || !idx_is_const) { ret = nxt_var_query_init(&r->var_query, r, r->mem_pool); @@ -279,10 +292,10 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, } if (idx_is_const) { - nxt_var_raw(conf->index, &ctx->index); + nxt_var_raw(index, &ctx->index); } else { - nxt_var_query(task, r->var_query, conf->index, &ctx->index); + nxt_var_query(task, r->var_query, index, &ctx->index); } if (shr_is_const) { @@ -698,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); diff --git a/test/test_static.py b/test/test_static.py index 2190901..7fe40b6 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -34,7 +34,7 @@ class TestStatic(TestApplicationProto): { "action": { "share": option.temp_dir + "/assets$uri", - "index": "$host.html" + "index": ["idontexist", "$host.html"] } } ], -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:02 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:02 +0100 Subject: [PATCH v4 05/12] nxt_http_static_ctx_t: rename field 'index' to 'share_idx' In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-6-alx.manpages@gmail.com> Having a configurable index filename will require adding an index field to this structure. The most natural name for that field is 'index', so the current index field should be renamed to allow for that. A sensible name is 'share_idx', since it's the index of the shares array in 'nxt_http_static_conf_t'. Instead of 'share_index' I opted for the shorter 'share_idx'. Also, when 'index' allows an array of filenames in a following commit, another similar variable 'index_idx' should be created, and having a different prefix and suffix seems more readable than for example 'index_index'. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_static.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 6b7cee7..663f896 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -33,7 +33,7 @@ typedef struct { #if (NXT_HAVE_OPENAT2) nxt_str_t chroot; #endif - uint32_t index; + uint32_t share_idx; uint8_t need_body; /* 1 bit */ } nxt_http_static_ctx_t; @@ -218,7 +218,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, conf = ctx->action->u.conf; - share = &conf->shares[ctx->index]; + share = &conf->shares[ctx->share_idx]; #if (NXT_DEBUG) nxt_str_t shr; @@ -245,7 +245,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_var_raw(share->var, &ctx->share); #if (NXT_HAVE_OPENAT2) - if (conf->chroot != NULL && ctx->index == 0) { + if (conf->chroot != NULL && ctx->share_idx == 0) { nxt_var_raw(conf->chroot, &ctx->chroot); } #endif @@ -262,7 +262,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_var_query(task, r->var_query, share->var, &ctx->share); #if (NXT_HAVE_OPENAT2) - if (conf->chroot != NULL && ctx->index == 0) { + if (conf->chroot != NULL && ctx->share_idx == 0) { nxt_var_query(task, r->var_query, conf->chroot, &ctx->chroot); } #endif @@ -357,7 +357,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data) nxt_uint_t resolve; nxt_http_static_share_t *share; - share = &conf->shares[ctx->index]; + share = &conf->shares[ctx->share_idx]; resolve = conf->resolve; chr = &ctx->chroot; @@ -659,9 +659,9 @@ nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r, action = ctx->action; conf = action->u.conf; - ctx->index++; + ctx->share_idx++; - if (ctx->index < conf->nshares) { + if (ctx->share_idx < conf->nshares) { nxt_http_static_iterate(task, r, ctx); return; } -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:06 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:06 +0100 Subject: [PATCH v4 09/12] Static: variables in the "index" option In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-10-alx.manpages@gmail.com> This adds support for variables in the "index" option. An example: { "share": "/srv/www/data/static/$uri", "index": "$method.html" } When is requested, will be served. === test_static.py: Rename to , to be able to test this feature, and set "index": "$host.html>". I also tried this feature in my own computer, where I tried the following: - Setting "index" to "$method.html", and check that is being served. - Not setting index, and check that is being served. - Setting "index" to "$asdf", and check that the configuration fails: { "error": "Invalid configuration.", "detail": "Unknown variable \"asdf\" in the \"index\" value." } Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- docs/changes.xml | 6 ++++++ src/nxt_conf_validation.c | 1 + src/nxt_http_static.c | 29 +++++++++++++++++++++-------- test/test_static.py | 13 +++++++------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/docs/changes.xml b/docs/changes.xml index 07f3c83..8931165 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -18,6 +18,12 @@ date="" time="" packager="Andrei Belov <defan at nginx.com>"> + + +variables support in the "index" option. + + + new "index" option to specify a custom index file name. diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index bdc38b0..6236720 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -648,6 +648,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { }, { .name = nxt_string("index"), .type = NXT_CONF_VLDT_STRING, + .flags = NXT_CONF_VLDT_VAR, }, { .name = nxt_string("types"), .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 2a176d0..57d8ca8 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -19,7 +19,7 @@ typedef struct { typedef struct { nxt_uint_t nshares; nxt_http_static_share_t *shares; - nxt_str_t index; + nxt_var_t *index; #if (NXT_HAVE_OPENAT2) nxt_var_t *chroot; nxt_uint_t resolve; @@ -115,12 +115,19 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, } if (acf->index == NULL) { - conf->index = default_index; + str = default_index; } else { - nxt_conf_get_string(acf->index, &conf->index); + nxt_conf_get_string(acf->index, &str); } + var = nxt_var_compile(&str, mp, 1); + if (nxt_slow_path(var == NULL)) { + return NXT_ERROR; + } + + conf->index = var; + #if (NXT_HAVE_OPENAT2) if (acf->chroot.length > 0) { nxt_str_t chr, shr; @@ -226,7 +233,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; + nxt_bool_t shr_is_const, idx_is_const; conf = ctx->action->u.conf; @@ -237,7 +244,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, nxt_str_t idx; nxt_var_raw(share->var, &shr); - idx = conf->index; + nxt_var_raw(conf->index, &idx); #if (NXT_HAVE_OPENAT2) nxt_str_t chr; @@ -257,8 +264,9 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #endif /* NXT_DEBUG */ shr_is_const = share->is_const; + idx_is_const = nxt_var_is_const(conf->index); - if (!shr_is_const) { + if (!shr_is_const || !idx_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); @@ -266,7 +274,12 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, } } - ctx->index = conf->index; + if (idx_is_const) { + nxt_var_raw(conf->index, &ctx->index); + + } else { + nxt_var_query(task, r->var_query, conf->index, &ctx->index); + } if (shr_is_const) { nxt_var_raw(share->var, &ctx->share); @@ -287,7 +300,7 @@ nxt_http_static_iterate(nxt_task_t *task, nxt_http_request_t *r, #endif } - if (shr_is_const) { + if (shr_is_const && idx_is_const) { nxt_http_static_send_ready(task, r, ctx); } else { diff --git a/test/test_static.py b/test/test_static.py index 70ae676..2190901 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -14,7 +14,8 @@ class TestStatic(TestApplicationProto): def setup_method(self): os.makedirs(option.temp_dir + '/assets/dir') - with open(option.temp_dir + '/assets/index_.html', 'w') as index, open( + with open(option.temp_dir + '/assets/localhost.html', 'w' + ) as index, open( option.temp_dir + '/assets/README', 'w' ) as readme, open( option.temp_dir + '/assets/log.log', 'w' @@ -33,7 +34,7 @@ class TestStatic(TestApplicationProto): { "action": { "share": option.temp_dir + "/assets$uri", - "index": "index_.html" + "index": "$host.html" } } ], @@ -91,7 +92,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2' def test_static_index(self): - assert self.get(url='/index_.html')['body'] == '0123456789', 'index' + assert self.get(url='/localhost.html')['body'] == '0123456789', 'index' assert self.get(url='/')['body'] == '0123456789', 'index 2' assert self.get(url='//')['body'] == '0123456789', 'index 3' assert self.get(url='/.')['body'] == '0123456789', 'index 4' @@ -100,7 +101,7 @@ class TestStatic(TestApplicationProto): assert self.get(url='/#blah')['body'] == '0123456789', 'index anchor' assert self.get(url='/dir/')['status'] == 404, 'index not found' - resp = self.get(url='/index_.html/') + resp = self.get(url='/localhost.html/') assert resp['status'] == 404, 'index not found 2 status' assert ( resp['headers']['Content-Type'] == 'text/html' @@ -124,7 +125,7 @@ class TestStatic(TestApplicationProto): assert etag != etag_2, 'different ETag' assert etag == self.get(url='/')['headers']['ETag'], 'same ETag' - with open(temp_dir + '/assets/index_.html', 'w') as f: + with open(temp_dir + '/assets/localhost.html', 'w') as f: f.write('blah') assert etag != self.get(url='/')['headers']['ETag'], 'new ETag' @@ -263,7 +264,7 @@ class TestStatic(TestApplicationProto): == 'text/x-code/x-blah/x-blah' ), 'mime_types string case insensitive' assert ( - self.get(url='/index_.html')['headers']['Content-Type'] + self.get(url='/localhost.html')['headers']['Content-Type'] == 'text/plain' ), 'mime_types html' assert ( -- 2.34.1 From alx.manpages at gmail.com Thu Dec 23 19:25:05 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 20:25:05 +0100 Subject: [PATCH v4 08/12] nxt_http_static_iterate(): generalize code In-Reply-To: <20211219013030.51372-1-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> Message-ID: <20211223192508.12146-9-alx.manpages@gmail.com> 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 Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- 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 From max.romanov at nginx.com Thu Dec 23 19:35:20 2021 From: max.romanov at nginx.com (Max Romanov) Date: Thu, 23 Dec 2021 22:35:20 +0300 Subject: [PATCH] update java components to their recent versions In-Reply-To: References: Message-ID: Hello, Unfortunately, we cannot easily upgrade Eclipse packages since they are not supporting Java 8 anymore (https://www.eclipse.org/lists/eclipse-dev/msg11703.html). We have a following options: - stay where we are with ECJ and Jetty packages, keep upgrading Tomcat and Classgraph; - drop Java 8 support and move to Java 11; - use old versions for Java 8 and more recent for other (bad option); ? Max > On 15 Dec 2021, at 07:03, Sergey A. Osokin wrote: > > Hi, > > here's the patch to update NGINX Unit's java components to their > recent versions. > > Thank you. > > -- > Sergey A. Osokin > _______________________________________________ > unit mailing list > unit at nginx.org > https://mailman.nginx.org/mailman/listinfo/unit From alx.manpages at gmail.com Thu Dec 23 20:02:05 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Thu, 23 Dec 2021 21:02:05 +0100 Subject: [PATCH v4 12/12] Static: multiple paths in the "index" option In-Reply-To: <20211223192508.12146-13-alx.manpages@gmail.com> References: <20211219013030.51372-1-alx.manpages@gmail.com> <20211223192508.12146-13-alx.manpages@gmail.com> Message-ID: On 12/23/21 20:25, Alejandro Colomar wrote: > diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c > index 16744f2..30b7fd6 100644 > --- a/src/nxt_http_static.c > +++ b/src/nxt_http_static.c > @@ -698,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++; > + } I'll optimize this to only iterate over index if (ctx->share.start[shr->length - 1] == '/') -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From alx.manpages at gmail.com Thu Dec 23 20:14:56 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Thu, 23 Dec 2021 21:14:56 +0100 Subject: [PATCH v4 13/13] Static: optimize "index" iteration In-Reply-To: <20211223192508.12146-1-alx.manpages@gmail.com> References: <20211223192508.12146-1-alx.manpages@gmail.com> Message-ID: <20211223201454.13475-1-alx.manpages@gmail.com> Iterate over "index" only if "share" is a directory. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- src/nxt_http_static.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 30b7fd6..50f63b2 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -711,7 +711,13 @@ nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r, action = ctx->action; conf = action->u.conf; - ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; + if (ctx->share.start[ctx->share.length - 1] == '/') { + ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; + + } else { + ctx->index_idx = 0; + } + if (ctx->index_idx == 0) { ctx->share_idx++; } -- 2.34.1 From osa at freebsd.org.ru Thu Dec 23 20:31:16 2021 From: osa at freebsd.org.ru (Sergey A. Osokin) Date: Thu, 23 Dec 2021 23:31:16 +0300 Subject: [PATCH] update java components to their recent versions In-Reply-To: References: Message-ID: Hi Max, thanks for the update. On Thu, Dec 23, 2021 at 10:35:20PM +0300, Max Romanov wrote: > > On 15 Dec 2021, at 07:03, Sergey A. Osokin wrote: > > > > here's the patch to update NGINX Unit's java components to their > > recent versions. > > Unfortunately, we cannot easily upgrade Eclipse packages since they are > not supporting Java 8 anymore > (https://www.eclipse.org/lists/eclipse-dev/msg11703.html). > > We have a following options: > - stay where we are with ECJ and Jetty packages, keep upgrading Tomcat > and Classgraph; > - drop Java 8 support and move to Java 11; > - use old versions for Java 8 and more recent for other (bad option); My thoughts we'd need to switch default supported version from java8 to java11, and, if that's possible, continue to support java8. If that's not possible to continue to support java8, we'd need to drop support of that version of java, in any cases premium support for that version will be finished shortly, in March 2022. I'd like to add a note here: there are many frameworks support java11+ only (i.e. no support for java8) and dropped support for java8 at the moment (I'd like to point to at least to JavaFX). Thank you. -- Sergey A. Osokin From vbart at nginx.com Fri Dec 24 00:24:00 2021 From: vbart at nginx.com (Valentin V. Bartenev) Date: Fri, 24 Dec 2021 03:24:00 +0300 Subject: [PATCH v4 13/13] Static: optimize "index" iteration In-Reply-To: <20211223201454.13475-1-alx.manpages@gmail.com> References: <20211223192508.12146-1-alx.manpages@gmail.com> <20211223201454.13475-1-alx.manpages@gmail.com> Message-ID: <11888402.O9o76ZdvQC@vbart-laptop> On Thursday, 23 December 2021 23:14:56 MSK Alejandro Colomar wrote: > Iterate over "index" only if "share" is a directory. > > Signed-off-by: Alejandro Colomar > Cc: Nginx Unit > Cc: "Valentin V. Bartenev" > Cc: Zhidao HONG > Cc: Igor Sysoev > Cc: Oisin Canty > --- > src/nxt_http_static.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c > index 30b7fd6..50f63b2 100644 > --- a/src/nxt_http_static.c > +++ b/src/nxt_http_static.c > @@ -711,7 +711,13 @@ nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r, > action = ctx->action; > conf = action->u.conf; > > - ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; > + if (ctx->share.start[ctx->share.length - 1] == '/') { > + ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; > + > + } else { > + ctx->index_idx = 0; > + } > + [..] What's the reason for this "else"? Isn't ctx->index_idx always 0 in this case? -- Valentin From alx.manpages at gmail.com Fri Dec 24 12:16:14 2021 From: alx.manpages at gmail.com (Alejandro Colomar (man-pages)) Date: Fri, 24 Dec 2021 13:16:14 +0100 Subject: [PATCH v4 13/13] Static: optimize "index" iteration In-Reply-To: <11888402.O9o76ZdvQC@vbart-laptop> References: <20211223192508.12146-1-alx.manpages@gmail.com> <20211223201454.13475-1-alx.manpages@gmail.com> <11888402.O9o76ZdvQC@vbart-laptop> Message-ID: <1bb6332b-a07e-ee36-66d6-6c5b61e648c2@gmail.com> On 12/24/21 01:24, Valentin V. Bartenev wrote: >> diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c >> index 30b7fd6..50f63b2 100644 >> --- a/src/nxt_http_static.c >> +++ b/src/nxt_http_static.c >> @@ -711,7 +711,13 @@ nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r, >> action = ctx->action; >> conf = action->u.conf; >> >> - ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; >> + if (ctx->share.start[ctx->share.length - 1] == '/') { >> + ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; >> + >> + } else { >> + ctx->index_idx = 0; >> + } >> + > [..] > > What's the reason for this "else"? > Isn't ctx->index_idx always 0 in this case? Oops, you're right. I'll remove it. Thanks, Alex -- Alejandro Colomar Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ From alx.manpages at gmail.com Fri Dec 24 12:20:01 2021 From: alx.manpages at gmail.com (Alejandro Colomar) Date: Fri, 24 Dec 2021 13:20:01 +0100 Subject: [PATCH v5 13/13] Static: optimize "index" iteration In-Reply-To: <20211223201454.13475-1-alx.manpages@gmail.com> References: <20211223201454.13475-1-alx.manpages@gmail.com> Message-ID: <20211224122000.16186-1-alx.manpages@gmail.com> Iterate over "index" only if "share" is a directory. Signed-off-by: Alejandro Colomar Cc: Nginx Unit Cc: "Valentin V. Bartenev" Cc: Zhidao HONG Cc: Igor Sysoev Cc: Oisin Canty --- v5: - Remove unnecessary 'else' (reported by Valentin) - Only patch 13/13 is changed; patches v4 01..12/12 still apply. src/nxt_http_static.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 30b7fd6..28ec592 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->index_idx = (ctx->index_idx + 1) % conf->nindices; + if (ctx->share.start[ctx->share.length - 1] == '/') { + ctx->index_idx = (ctx->index_idx + 1) % conf->nindices; + } + if (ctx->index_idx == 0) { ctx->share_idx++; } -- 2.34.1