Commit Graph

2571 Commits

Author SHA1 Message Date
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
Andrei Zeliankou
e88e16d11e Tests: added tests for NJS loadable modules. 2023-05-10 13:02:52 +01:00
Konstantin Pavlov
dc03914418 Regenerated dockerfiles. 2023-05-09 20:20:28 -07:00
Liam Crilly
d481801907 Docker: show welcome page on port 80 when entrypoint.d is empty.
The entrypoint script now performs a default configuration when no useful
files are found in /docker-entrypoint.d/

The default configuration serves a welcome page in response to all
requests, using Markdown unless text/html is sent in the Accept header.

This provides a useful 'hello world' experience when running a Unit
container for the first time.
2023-05-09 22:53:18 +01:00
Konstantin Pavlov
8ab16f71fe Docker: tagged minimal variant as latest. 2023-05-05 17:20:10 -07:00
Konstantin Pavlov
5b98d87e52 Docker: Makefile housekeeping. 2023-05-05 17:20:06 -07:00
Konstantin Pavlov
6e548cbb30 Docker: added a way to generate multiple versions of an image. 2023-05-05 17:19:55 -07:00
Konstantin Pavlov
7a77f48a25 Packages: added Ubuntu 23.04 "lunar" support. 2023-05-03 16:13:36 -07:00
Liam Crilly
20a5fd44ac Docker: add support for JavaScript modules. 2023-05-09 19:19:36 +01:00
Zhidao HONG
a3c3a29493 NJS: supported loadable modules. 2023-05-08 16:00:25 +08:00
Andrei Zeliankou
56af7bb825 Tests: added tests for the URI rewrite. 2023-05-09 13:52:09 +01:00
Zhidao HONG
14d6d97bac HTTP: added basic URI rewrite.
This commit introduced the basic URI rewrite. It allows users to change request URI. Note the "rewrite" option ignores the contained query if any and the query from the request is preserverd.
An example:
"routes": [
    {
        "match": {
            "uri": "/v1/test"
        },
        "action": {
            "return": 200
        }
    },
    {
        "action": {
            "rewrite": "/v1$uri",
            "pass": "routes"
        }
    }
]

Reviewed-by: Alejandro Colomar <alx@nginx.com>
2023-04-20 23:20:41 +08:00
Alejandro Colomar
8843e30e82 Docs: removed incorrect Pp call in unitd.8.
Pp is used to separate paragraphs, not to introduce them.  A Pp macro
call right after Sh is wrong, and it is ignored by the formatter, which
reports a warning about it.

Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 18:07:22 +02:00
Alejandro Colomar
7417987923 Docs: using appropriate mdoc(7) macros for URIs in unitd.8.
Reviewed-by: Artem Konev <a.konev@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 17:47:28 +02:00
Alejandro Colomar
8e849db4e6 Docs: changed Authors section to Copyright section in unitd.8.
The Authors section is meant to list the main authors.  However, the
section only contained the copyright notice, so the Copyright section
seems more appropriate.  While we change that, it makes sense to also
specify the license, and update the copyright year.

Reviewed-by: Liam Crilly <liam@nginx.com>
Reviewed-by: Artem Konev <a.konev@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 17:47:28 +02:00
Alejandro Colomar
f994b232ff Docs: updated unitd.8 date.
We've applied significant changes to the page, so let's update the date.
While we're at it, let's change it to use ISO 8601 format for the date.

Reviewed-by: Artem Konev <a.konev@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 17:47:28 +02:00
Alejandro Colomar
3d76bc5996 Docs: setting the project name in unitd.8.
Not setting it produces the default value of 'BSD' or 'GNU', depending
on the software formatting the manual page.  We're neither, so let's
specify our project name.  See groff_mdoc(7).  While mandoc_mdoc(7)
formally says that .Os is only for the operating system, and not for the
package name, that's an oversimplification, and only meant for software
inherent to the OS.  For portable software, mandoc(1)'s (and OpenBSD's)
maintainer Ingo Schwarze agreed that it is more sensible to specify the
project name (and optionally, the version).

Reviewed-by: Artem Konev <a.konev@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 17:47:28 +02:00
Alejandro Colomar
c2bb129e47 Docs: documenting the renamed directory flags in unitd.8.
Reviewed-by: Artem Konev <a.konev@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 17:47:28 +02:00
Alejandro Colomar
7fdd5b035f Docs: not using shouty caps in unitd.8.
There was a recent unanimous agreement by maintainers of groff, mandoc,
the Linux man-pages, and other relevant programmers, that manual pages
should not use uppercase unnecessarily.  Use of uppercase in the title
and in the section's titles dates from before one could use bold,
italics, and other such formatting, so that it was the way of giving
more importance to certain parts of a page.  Nowadays, we use bold, so
uppercase is unnecessary.

Moreover, using uppercase in the title is bad, since it removes
information.  If we keep the exact casing used in the program (or
function) name, we provide more information.  And anyway, if users want
to read in uppercase, they can program certain mdoc(7) or man(7) macros
to transform their arguments into uppercase.  This could be done via
</etc/groff/mdoc.local> and </etc/groff/man.local>.

There's a plan of transforming OpenBSD pages and the Linux man-pages to
stop using uppercase.  Other projects may join.  That will likely happen
in the following months.  Let's align with this.

Reviewed-by: Artem Konev <a.konev@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-05-08 17:47:28 +02:00