summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)AuthorFilesLines
2022-04-28Tests: Changed tests to accept variables in "location".Alejandro Colomar1-4/+4
2022-04-28Supporting variables in "location".Alejandro Colomar3-37/+153
............ Description: ............ Before this commit, the encoded URI could be calculated at configuration time. Now, since variables can only be resolved at request time, we have different situations: - "location" contains no variables: In this case, we still encode the URI in the conf structure, at configuration time, and then we just copy the resulting string to the ctx structure at request time. - "location" contains variables: In this case, we compile the var string at configure time, then when we resolve it at request time, and then we encode the string. In both cases, as was being done before, if the string is empty, either before or after resolving variables, we skip the encoding. ........... Usefulness: ........... An example of why this feature may be useful is redirecting HTTP to HTTPS with something like: "action": { "return": 301, "location": "https://${host}${uri}" } ..... Bugs: ..... This feature conflicts with the relevant RFCs in the following: '$' is used for Unit variables, but '$' is a reserved character in a URI, to be used as a sub-delimiter. However, it's almost never used as that, and in fact, other parts of Unit already conflict with '$' being a reserved character for use as a sub-delimiter, so this is at least consistent in that sense. VBart suggested an easy workaround if we ever need it: adding a variable '$sign' which resolves to a literal '$'. ...... Notes: ...... An empty string is handled as if "location" wasn't specified at all, so no Location header is sent. This is incorrect, and the code is slightly misleading. The Location header consists of a URI-reference[1], which might be a relative one, which itself might consist of an empty string[2]. [1]: <https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2> [2]: <https://stackoverflow.com/a/43338457> Now that we have variables, it's more likely that an empty Location header will be requested, and we should handle it correctly. I think in a future commit we should modify the code to allow differentiating between an unset "location" and an empty one, which should be treated as any other "location" string. ................. Testing (manual): ................. { "listeners": { "*:80": { "pass": "routes/str" }, "*:81": { "pass": "routes/empty" }, "*:82": { "pass": "routes/var" }, "*:83": { "pass": "routes/enc-str" }, "*:84": { "pass": "routes/enc-var" } }, "routes": { "str": [ { "action": { "return": 301, "location": "foo" } } ], "empty": [ { "action": { "return": 301, "location": "" } } ], "var": [ { "action": { "return": 301, "location": "$host" } } ], "enc-str": [ { "action": { "return": 301, "location": "f%23o#o" } } ], "enc-var": [ { "action": { "return": 301, "location": "f%23o${host}#o" } } ] } } $ curl --dump-header - localhost:80 HTTP/1.1 301 Moved Permanently Location: foo Server: Unit/1.27.0 Date: Thu, 07 Apr 2022 23:30:06 GMT Content-Length: 0 $ curl --dump-header - localhost:81 HTTP/1.1 301 Moved Permanently Server: Unit/1.27.0 Date: Thu, 07 Apr 2022 23:30:08 GMT Content-Length: 0 $ curl --dump-header - localhost:82 HTTP/1.1 301 Moved Permanently Location: localhost Server: Unit/1.27.0 Date: Thu, 07 Apr 2022 23:30:15 GMT Content-Length: 0 $ curl --dump-header - -H "Host: bar" localhost:82 HTTP/1.1 301 Moved Permanently Location: bar Server: Unit/1.27.0 Date: Thu, 07 Apr 2022 23:30:23 GMT Content-Length: 0 $ curl --dump-header - -H "Host: " localhost:82 HTTP/1.1 301 Moved Permanently Server: Unit/1.27.0 Date: Thu, 07 Apr 2022 23:30:29 GMT Content-Length: 0 $ curl --dump-header - localhost:83 HTTP/1.1 301 Moved Permanently Location: f%23o#o Server: Unit/1.27.0 Date: Sat, 09 Apr 2022 11:22:23 GMT Content-Length: 0 $ curl --dump-header - -H "Host: " localhost:84 HTTP/1.1 301 Moved Permanently Location: f%23o#o Server: Unit/1.27.0 Date: Sat, 09 Apr 2022 11:22:44 GMT Content-Length: 0 $ curl --dump-header - -H "Host: alx" localhost:84 HTTP/1.1 301 Moved Permanently Location: f%23oalx#o Server: Unit/1.27.0 Date: Sat, 09 Apr 2022 11:22:52 GMT Content-Length: 0 $ curl --dump-header - -H "Host: a#l%23x" localhost:84 HTTP/1.1 301 Moved Permanently Location: f%2523oa#l%2523x%23o Server: Unit/1.27.0 Date: Sat, 09 Apr 2022 11:23:09 GMT Content-Length: 0 $ curl --dump-header - -H "Host: b##ar" localhost:82 HTTP/1.1 301 Moved Permanently Location: b#%23ar Server: Unit/1.27.0 Date: Sat, 09 Apr 2022 11:25:01 GMT Content-Length: 0
2022-04-28Workarounded Clang bug triggered by Ruby.Alejandro Colomar1-1/+27
Add -fdeclspec to NXT_RUBY_CFLAGS for Clang, if it's available. Clang incorrectly reports 1 for __has_declspec_attribute(x) in some cases, such as MacOS or Cygwin. That causes ruby code to break. ruby added -fdeclspec to their CFLAGS in 2019 to workaround this bug, since it enables __declspec() and therefore, the compiler behavior matches what it reports. Since we don't know what are all the architectures that trigger the clang bug, let's add the flag for all of them (especially since it should be harmless). Add this workaround only at the time of configuring the ruby module. This way we don't clutter the global NXT_CFLAGS with an unnecessary flag. Link: unit bug <https://github.com/nginx/unit/issues/653> Link: ruby bug <https://bugs.ruby-lang.org/issues/18616> Link: LLVM bug <https://github.com/llvm/llvm-project/issues/49958> Commit: LLVM: Add -fdeclspec <d170c4b57a91adc74ca89c6d4af616a00323b12c> Commit: ruby: Use -fdeclspec <0958e19ffb047781fe1506760c7cbd8d7fe74e57>
2022-04-27Added NXT_MAYBE_UNUSED for __attribute__((__unused__)).Alejandro Colomar3-1/+31
When testing some configurations of compilers and OSes, I noticed that clang(1) 13 on Debian caused a function to be compiled but unused, and the compiler triggered a compile error. To avoid that error, use __attribute__((__unused__)). Let's call our wrapper NXT_MAYBE_UNUSED, since it describes itself more precisely than the GCC attribute name. It's also the name that C2x (likely C23) has given to the standard attribute, which is [[maybe_unused]], so it's also likely to be more readable because of that name being in ISO C.
2022-04-26Fixed indentation.Alejandro Colomar13-38/+38
Some lines (incorrectly) had an indentation of 3 or 5, or 7 or 9, or 11 or 13, or 15 or 17 spaces instead of 4, 8, 12, or 16. Fix them. Found with: $ find src -type f | xargs grep -n '^ [^ ]'; $ find src -type f | xargs grep -n '^ [^ *]'; $ find src -type f | xargs grep -n '^ [^ ]'; $ find src -type f | xargs grep -n '^ [^ *]'; $ find src -type f | xargs grep -n '^ [^ +]'; $ find src -type f | xargs grep -n '^ [^ *+]'; $ find src -type f | xargs grep -n '^ [^ +]'; $ find src -type f | xargs grep -n '^ [^ *+]';
2022-04-26Removed special cases for non-NXT_CONF_VALUE_ARRAY.Alejandro Colomar5-113/+27
The previous commit added more generic APIs for handling NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together. 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.
2022-04-26Added new array APIs that also work with non-arrays.Alejandro Colomar2-0/+30
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_or_1(): Similar to 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_or_itself(), which will return a correct element for such loops. nxt_conf_get_array_element_or_itself(): Similar to 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 API can be reused.
2022-04-26Added 'const' for read-only function parameter.Alejandro Colomar2-2/+3
That parameter is not being modified in the function. Make it 'const' to allow passing 'static const' variables.
2022-04-12Tests: added check for zombie processes.Andrei Zeliankou1-0/+58
2022-04-11Tests: style.Andrei Zeliankou36-343/+291
2022-02-22Workaround for the warning in nxt_realloc() on GCC 12.Zhidao HONG2-3/+16
This closes #639 issue on Github.
2022-02-15Tests: added test with long certificate chain.Andrei Zeliankou1-0/+45
2022-02-15Updated copyright notice.Valentin Bartenev8-34/+80
2022-02-14Certificates: fixed crash when reallocating chain.Zhidao HONG2-1/+7
2022-02-09Python: fixing debug message field type.Max Romanov1-1/+2
Introduced in the 78864c9d5ba8 commit. Sorry about that.
2022-02-08Python: fixing incorrect function object dereference.Max Romanov2-6/+19
The __call__ method can be native and not be a PyFunction type. A type check is thus required before accessing op_code and other fields. Reproduced on Ubuntu 21.04, Python 3.9.4 and Falcon framework: here, the App.__call__ method is compiled with Cython, so accessing op_code->co_flags is invalid; accidentally, the COROUTINE bit is set which forces the Python module into the ASGI mode. The workaround is explicit protocol specification. Note: it is impossible to specify the legacy mode for ASGI.
2022-01-31Tests: removed TestApplicationTLS.get_server_certificate().Andrei Zeliankou14-60/+61
distutils.version is replaced by packaging.version. Also minor style fixes.
2022-01-13Docker: bumped Python image version.Konstantin Pavlov1-1/+1
2022-01-10Tests: using modules in Go.Max Romanov5-46/+41
2021-12-27Java: fixing multiple SCI initializations.Max Romanov2-4/+21
- Ignoring Tomcat WebSocket container initialization. - Renaming application class loader to UnitClassLoader to avoid development environment enablement in Spring Boot. This closes #609 issue on GitHub.
2021-12-27Perl: creating input and error streams if closed.Max Romanov7-167/+166
Application handler can do anything with a stream object (including close it). Once the stream is closed, Unit creates a new stream. This closes #616 issue on GitHub.
2021-12-17Docker: bumped PHP image version.Konstantin Pavlov1-1/+1
2021-12-01Docker: made Dockerfiles architecture agnostic.Konstantin Pavlov2-2/+6
2021-12-12Tests: fixed type of applications.Andrei Zeliankou9-23/+23
2021-12-11Tests: added more OPcache tests.Andrei Zeliankou4-13/+66
2021-12-10Tests: fixed path to the "php.ini" file.Andrei Zeliankou1-2/+10
2021-12-03Fixed debug message broken in 45b25ffb2e8c.Zhidao HONG1-1/+2
2021-12-03Printing version in "./configure" output.Valentin Bartenev2-1/+3
2021-12-03Merged with the 1.26 branch.Valentin Bartenev11-15/+63
2021-12-02Unit 1.26.1 release.Valentin Bartenev1-0/+1
2021-12-02Generated Dockerfiles for Unit 1.26.1.1.26.1Valentin Bartenev8-8/+8
2021-12-02Added version 1.26.1 CHANGES.Valentin Bartenev2-2/+20
2021-12-02Reordered changes for 1.26.1 by significance (subjective).Valentin Bartenev1-7/+7
2021-12-02Fixed grammar in "changes.xml".Artem Konev1-1/+1
2021-12-02Fixed grammar in "changes.xml".Artem Konev1-1/+1
2021-12-02Packages: added systemd service for debug binary.Andrei Belov4-5/+50
2021-12-02Packages: added systemd service for debug binary.Andrei Belov4-5/+50
2021-12-01Disabling SCM_CREDS usage on DragonFly BSD.Max Romanov2-30/+38
DragonFly BSD supports SCM_CREDS and SCM_RIGHTS, but only the first control message is passed correctly while the second one isn't processed by the kernel. This closes #599 issue on GitHub.
2021-12-01Disabling SCM_CREDS usage on DragonFly BSD.Max Romanov2-30/+38
DragonFly BSD supports SCM_CREDS and SCM_RIGHTS, but only the first control message is passed correctly while the second one isn't processed by the kernel. This closes #599 issue on GitHub.
2021-12-01Fixing prototype process crash.Max Romanov2-0/+9
A prototype stores linked application processes structures. When an application process terminates, it's removed from the list. To avoid double removal, the pointer to the next element should be set to NULL. The issue was introduced in c8790d2a89bb.
2021-12-01Fixing prototype process crash.Max Romanov2-0/+9
A prototype stores linked application processes structures. When an application process terminates, it's removed from the list. To avoid double removal, the pointer to the next element should be set to NULL. The issue was introduced in c8790d2a89bb.
2021-12-01Fixing uninitialized structure field.Max Romanov1-0/+1
Port's "data" field may be used by application and thus need to be set to NULL. The issue was introduced in the f8a0992944df commit. Found by Coverity (CID 374352).
2021-12-01Logging of the daemon version on startup.Valentin Bartenev1-1/+1
2021-12-01Logging of the daemon version on startup.Valentin Bartenev1-1/+1
2021-12-01Tests: fixed skipping tests with disabled OPcache.Andrei Zeliankou1-1/+1
2021-12-01Tests: fixed skipping tests with disabled OPcache.Andrei Zeliankou1-1/+1
2021-11-30Docker: respect the binary from CMD in the entrypoint.Konstantin Pavlov1-1/+1
2021-12-01Packages: adjusted debhelper minimal version for Debian/Ubuntu.Andrei Belov3-6/+6
Forgotten in 199a11eceb3c. While here, Standards-Version increased to 4.1.4 (matches Ubuntu 18.04 as the oldest supported distro).
2021-11-30Docker: respect the binary from CMD in the entrypoint.Konstantin Pavlov1-1/+1
2021-12-01Packages: adjusted debhelper minimal version for Debian/Ubuntu.Andrei Belov3-6/+6
Forgotten in 199a11eceb3c. While here, Standards-Version increased to 4.1.4 (matches Ubuntu 18.04 as the oldest supported distro).