Commit graph

2389 commits

Author SHA1 Message Date
Zhidao HONG
9f04d6db63 HTTP: stored matched action in nxt_http_request_t.
No functional changes.
2023-08-09 14:36:16 +08:00
Konstantin Pavlov
497f08d15f NJS: explicitely require 0.8.0 or later versions in configure. 2023-07-11 13:02:43 -07:00
Artem Konev
142006528d Update README.md for Docker Official Image.
[Liam: rewrote commit message]
Acked-by: Liam Crilly <liam@nginx.com>
Cc: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-08-01 16:06:36 +02:00
Zhidao HONG
d0fdf5971f NJS: workaround for the warning in nxt_js_call() on Freebsd12 gcc. 2023-07-12 09:31:22 +08:00
Konstantin Pavlov
eb614f1147 contrib: updated njs to 0.8.0. 2023-07-11 11:40:41 -07:00
Andrei Zeliankou
2ad03caf32 Tests: added tests for response header variables. 2023-07-11 15:51:53 +01:00
Zhidao HONG
458722df55 Var: supported HTTP response header variables.
This commit adds the variable $response_header_NAME.
2023-07-01 12:18:22 +08:00
Zhidao HONG
c61ccec7b4 Variables refactoring.
This commit is to reimplement the variables with an unknown field
such as $header_{name} to make the parsing more generic,
it's a preparation for supporting response header variables.
2023-06-19 16:29:22 +08:00
Zhidao HONG
18d3637e4b NJS: supported 0.8.0. 2023-07-11 09:30:50 +08:00
Andrei Zeliankou
075c6a7038 Tests: check TLS methods availability more carefully. 2023-07-10 15:24:15 +01:00
Andrei Zeliankou
3c7743344b Tests: fixed exception handling. 2023-07-10 01:57:12 +01:00
Sergey A. Osokin
de885feb06 Update third-party components for Unit's Java module. 2023-07-07 09:54:23 -04:00
Alejandro Colomar
c185ae7512 Fixed indentation.
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-06-30 14:38:34 +02:00
Alejandro Colomar
543d478e12 Tools: setup-unit: ctl: added "edit" subcommand.
Almost equivalent to b42f6b1d ("Tools: unitc edit mode for interactive
configuration."), implemented by Liam in tools/unitc.

I chose to give preference to vi(1) over vim(1) because Debian has vi(1)
as part of update-alternatives(1), so that sysadmins can configure it to
be a symlink to their favourite vi(1) implementation or variant.

We're ignoring the errors of the commands due to having the SSH tunnel
open.  I should fix the script to use traps to close the tunnel on any
error, so we don't leak tunnels.  Then, we'll be able to not ignore
curl(1) or editor errors.  That will also probably allow moving the
tunneling code to the ctl command, thus deduplicating code.

Cc: Liam Crilly <liam@nginx.com>
Cc: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-06-30 14:35:59 +02:00
Alejandro Colomar
d73526d27c Tools: setup-unit: restart: added -l and -s flags.
Add flags for cleaning the log file and state dir.

Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-06-27 17:45:49 +02:00
Alejandro Colomar
2f46870a3f Tools: setup-unit: added restart command.
It restarts all running unitd instances.  This is useful when
recompiling unitd often, so that the latest build is running, without
having to manually kill unitd instances and re-run with the same exact
command line every time.

Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-06-27 17:45:49 +02:00
Alejandro Colomar
e165801732 Tools: setup-unit: ps: forcing full lines from ps(1).
Some ps(1) implementations trim lines to 80 columns, even if the output
is being piped.  Let's force ps(1) to output full lines with `ww`, which
is not in POSIX, but seems to be portable enough.

On 2023-06-08 13:19, Andrew Clayton wrote:
> Just for posterity...
>
> BusyBox ps(1) knows about a grand total of 2 options!
>
> BusyBox v1.35.0 (2022-11-19 10:13:10 UTC) multi-call binary.
>
> Usage: ps [-o COL1,COL2=HEADER] [-T]
>
> Show list of processes
>
>         -o COL1,COL2=HEADER     Select columns for display
>         -T                      Show threads
>
> But at least it doesn't make it worse.  In fact all of these three do
> exactly the same thing
>
> ps
> ps ax
> ps axww
>
> I.e it ignores any non option argument...
>
> It does however help on OpenIndiana...

Link: <https://github.com/nginx/unit/issues/875>
Link: <https://github.com/nginx/unit/issues/886>
Link: <https://github.com/nginx/unit/pull/885>
Cc: <https://github.com/mattxtaz>
Cc: Liam Crilly <liam@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-06-27 17:45:43 +02:00
Alejandro Colomar
7d6851055b Tools: setup-unit: using $0 is simpler.
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-06-27 17:42:32 +02:00
Andrei Zeliankou
0461e804c1 Tests: no caching for $uri variable. 2023-06-14 18:30:40 +01:00
Andrei Zeliankou
c183bd8749 Tests: get rid of classes in test files.
Class usage came from the unittest framework and it was always redundant
after migration to the pytest.  This commit removes classes from files
containing tests to make them more readable and understandable.
2023-06-14 18:20:09 +01:00
Andrei Zeliankou
c6d05191a0 Tests: removed alert skip, unnecessary after 1a48ea61fec8. 2023-06-12 17:28:42 +01:00
Zhidao HONG
a378f6aa31 HTTP: fixed variable caching.
When a variable is accessed in the Unit configuration, the value is cached.
This was useful prior to the URI rewrite feature, but now that the URI (more
precisely, the request target) can be rewritten, the contents of the variable
$uri (which contains the path part of the request target, and is decoded)
should not be cached anymore, or at least the cached value should be invalidated
after a URI rewrite.

Example:

{
	"rewrite": "/prefix$uri",
	"share": "$uri"
}

For a request line like GET /foo?bar=baz HTTP/1.1\r\n, the expected file
served in the response would be /prefix/foo, but due to the caching issue,
Unit currently serves /foo.
2023-05-25 00:27:55 +08:00
Andrei Zeliankou
ce2405ec3d Tests: prerequisites checking reworked.
Prerequisites check moved to the module level to simplify class structure.
Discovery and prerequisites checks functions moved to the separate files.
Introduced "require" fixture to provide per-test requirements check.
2023-06-12 14:16:59 +01:00
Konstantin Pavlov
a3b9b49cfb Packages: added Debian 12 "bookworm" support. 2023-06-07 17:39:27 -07:00
Liam Crilly
b42f6b1dc8 Tools: unitc edit mode for interactive configuration. 2023-06-07 14:45:35 +01:00
Liam Crilly
9ff59e6c4b Tools: improved ps(1) portability for unitc.
Improved cross-platform support by trying multiple ps(1) invocations to
obtain the unitd command line parameters. Additional error checking
detects when this process fails.

The first attempt uses `ps -wwo args=COMMAND -p` which has very broad
support and has the additional benefit of simplifying the output for
more reliable parsing of the process info. If that fails then we fall
back to simply `ps`.

The parsing of the process info has also changed. Instead of converting
'[]' into spaces we now convert them into explicit delimiters (using '^').
This is more reliable as it marks the beginning and the end of the info
we care about. Any trailing process information is now ignored (FreeBSD).

Additional error handling improves the robustness when starting unitd with
a different filename or from a relative path. In this case the control
socket and log file detection will fail when running `unitd --help`.
Additional error checking and messages are displayed when the control socket
cannot be determined. A single warning is shown when the log file cannot be
determined.
2023-06-01 17:53:12 +01:00
synodriver
b84f6ecad4 Python: Fix error checks in nxt_py_asgi_request_handler().
Signed-off-by: synodriver <diguohuangjiajinweijun@gmail.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
[ Re-word commit subject - Andrew ]
Fixes: c4c2f90c5b ("Python: ASGI server introduced.")
Closes: <https://github.com/nginx/unit/issues/895>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-06-01 00:25:40 +01:00
synodriver
93ed66958e Python: Add ASGI lifespan state support.
Lifespan state is a special dict in asgi lifespan scope, which allow
applications to persist data from the lifespan cycle to request/response
handling. The scope["state"] namespace provides a place to store these
sorts of things. The server will ensure that a shallow copy of the
namespace is passed into each subsequent request/response call into the
application.

Some frameworks are already taking advantage of this feature, for
example, starlette, and without this feature they wouldn't work
properly.

Signed-off-by: synodriver <diguohuangjiajinweijun@gmail.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
[ Minor code tweaks to avoid lines > 80 chars, static a function and
  re-work the PyMemberDef structure initialisation for Python <3.7
  and -Wwrite-strings compatibility - Andrew ]
Tested-by: <https://github.com/synodriver>
Tested-by: <https://github.com/hawiliali>
Closes: <https://github.com/nginx/unit/issues/864>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-06-01 00:25:03 +01:00
Andrei Zeliankou
31ff94add9 Tests: more fixtures.
Common methods from applications/proto.py converted to the fixtures.
sysctl check moved to the specific file where it is using.
Some options moved to the constructor to have early access.
2023-05-29 16:45:49 +01:00
Andrei Zeliankou
f55818059c Tests: Log reworked.
All log-related code moved to the log.py.
2023-05-29 14:23:52 +01:00
Andrei Zeliankou
b034bf6703 Tests: assertion related fixes. 2023-05-25 16:56:14 +01:00
Andrei Zeliankou
0132e552d0 Tests: "temp_dir" fixture used were possible. 2023-05-25 16:56:14 +01:00
Andrei Zeliankou
18fcc07c77 Tests: unified setup method usage.
To make fixtures accessible inside of setup methods in tests all these methods
are renamed to the "setup_method_fixture" and decorated by autouse flag.

Also all setup methods moved to the top of the files.
2023-05-25 16:56:14 +01:00
Andrei Zeliankou
3e4fa1e202 Tests: removed unused variables. 2023-05-25 14:26:12 +01:00
Alejandro Colomar
47cdfb6f30 Tests: fixed incorrect pointer assignment.
If we don't update the pointer before copying the request body, then we
get the behavior shown below.  After this patch, "foo\n" is rightly
appended at the end of the response body.

Request:

"GET / HTTP/1.1\r\nHost: _\nContent-Length: 4\n\nfoo\n"

Response body:

"""
Hello world!
foo
est data:
  Method: GET
  Protocol: HTTP/1.1
  Remote addr: 127.0.0.1
  Local addr: 127.0.0.1
  Target: /
  Path: /
  Fields:
    Host: _
    Content-Length: 4
  Body:
"""

Fixes: 1bb22d1e92 ("Unit application library.")
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-25 11:27:35 +02:00
Andrei Zeliankou
71f8c58f7f Updated copyright notice. 2023-05-24 16:27:24 +01:00
Andrei Zeliankou
3f655cbd07 Version bump. 2023-05-24 16:24:42 +01:00
Alejandro Colomar
578f3c4c11 Using names in .mailmap.
In this case, Andrew always committed under the same name, so it's not
strictly necessary.

This is for consistency, so that it's clearer whose is an email address.
It also makes it easier to sort the names alphabetically.

Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-21 01:06:26 +02:00
Alejandro Colomar
766a565b2f Added Alex to .mailmap.
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-21 01:06:26 +02:00
Alejandro Colomar
f32858dcb7 Added back deprecated options to unitd.
We renamed the options recently, with the intention of keeping the old
names as supported but deprecated for some time, before removal.  This
was done with the configure script options, but in the unitd binary, we
accidentally removed the old names, causing some unintended breakage.
Keep support for the old names, albeit with a deprecation message to
stderr, for some time, until we decide to remove them.

Fixes: 5a37171f73 ("Added default values for pathnames.")
Closes: <https://github.com/nginx/unit/issues/876>
Reported-by: El RIDO <elrido@gmx.net>
Acked-by: Liam Crilly <liam@nginx.com>
Acked-by: Artem Konev <a.konev@f5.com>
Acked-by: Timo Stark <t.stark@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Andrei Zeliankou <zelenkov@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-21 01:01:43 +02:00
Andrei Zeliankou
5f8d58d2a4 Tests: added tests for "server_version" option. 2023-05-19 18:27:41 +01:00
Andrei Zeliankou
aa57254674 Tests: added ASGI application with IPv6 address test. 2023-05-19 18:27:07 +01:00
Andrew Clayton
47683c4704 Python: Fix ASGI applications accessed over IPv6.
There are a couple of reports on GitHub about issues accessing Python
ASGI based applications over IPv6.

A request over IPv6 would result in an error like

2023/05/13 17:49:12 [alert] 47202#47202 [unit] #10: Python failed to create 'client' pair
2023/05/13 17:49:12 [alert] 47202#47202 [unit] Python failed to call 'loop.call_soon'
ValueError: invalid literal for int() with base 10: 'db8:1:1:1ee7:dead:beef:cafe'

The above error was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 765, in call_soon
    handle = self._call_soon(callback, args, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 781, in _call_soon
    handle = events.Handle(callback, args, self, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <class 'asyncio.events.Handle'> returned a result with an exception set

This issue occurred in the nxt_py_asgi_create_ip_address() function
where it tries to create an IP address / port number pair.

It does this by looking for the first ':' in the address and taking
everything after it as the port number. Like in the above error message,
if we tried to access the server @ 2001:db8:1:1:1ee7:dead:beef:cafe,
then we'd end up with the port number as 'db8:1:1:1ee7:dead:beef:cafe'.

There are two issues with this

 1) The IP address and port number are already flowed through
    separately.
 2) Even if (1) wasn't true, it would still be broken for IPv6 as we'd
    expect to a get an address literal like
    [2001:db8:1:1:1ee7:dead:beef:cafe]:8080, however there was no code to
    handle the []'s.

The fix is to simply not try looking for a port number. We pass a port
number into this function to use in the case where we don't find a port
number, we never will...

A further cleanup would be to flow through the server port number when
creating the 'server pair' PyTuple, rather than just using the hard
coded 80.

Closes: <https://github.com/nginx/unit/issues/793>
Closes: <https://github.com/nginx/unit/issues/874>
Reviewed-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-05-18 15:57:11 +01:00
Artem Konev
aa45d17dc6 Fixed broken links in README. 2023-05-10 21:15:17 +01:00
Artem Konev
51de0db7f5 Added the initial version of the OpenAPI specification. 2023-05-10 20:57:42 +01:00
Andrei Zeliankou
faf97dc060 Unit 1.30.0 release. 2023-05-10 17:44:20 +01:00
Andrei Zeliankou
fcf1628b2c Merged with the 1.29 branch. 2023-05-10 17:22:28 +01:00
Andrei Zeliankou
03718e0bdf Added version 1.30.0 CHANGES. 2023-05-10 16:53:01 +01:00
Andrei Zeliankou
ec275200f7 Edited "changes.xml" for the 1.30.0 release. 2023-05-10 16:07:25 +01:00
Artem Konev
014a5ab6cb Toned down proxy messaging in README. 2023-05-10 13:23:33 +01:00