<feed xmlns='http://www.w3.org/2005/Atom'>
<title>unit.git/src, branch 1.27.0</title>
<subtitle>Universal Web Application Server</subtitle>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/'/>
<entry>
<title>Node.js: fixed ES modules format in loader.mjs.</title>
<updated>2022-06-02T10:48:27+00:00</updated>
<author>
<name>Andrei Zeliankou</name>
<email>zelenkov@nginx.com</email>
</author>
<published>2022-06-02T10:48:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=bd80039e07500021664a10984977cf64902a4b81'/>
<id>bd80039e07500021664a10984977cf64902a4b81</id>
<content type='text'>
Before Node.js v16.14.0 the "format" value in defaultResolve
was ignored so error was hidden.  For more information see:
https://github.com/nodejs/node/pull/40980
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before Node.js v16.14.0 the "format" value in defaultResolve
was ignored so error was hidden.  For more information see:
https://github.com/nodejs/node/pull/40980
</pre>
</div>
</content>
</entry>
<entry>
<title>Logging a NULL pointer instead of passing it in the memcpy().</title>
<updated>2022-06-01T15:40:34+00:00</updated>
<author>
<name>Andrei Zeliankou</name>
<email>zelenkov@nginx.com</email>
</author>
<published>2022-06-01T15:40:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=caa05887ff70bbd6338b129959a234ef56f1a287'/>
<id>caa05887ff70bbd6338b129959a234ef56f1a287</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Var: Added $request_uri (as in NGINX).</title>
<updated>2022-05-31T10:40:02+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-05-26T12:38:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=9bf614cd0874e0ef9fda3145faacd3ef3a5fb0ed'/>
<id>9bf614cd0874e0ef9fda3145faacd3ef3a5fb0ed</id>
<content type='text'>
This supports a new variable $request_uri that contains the path
and the query (See RFC 3986, section 3).  Its contents are percent
encoded.  This is useful for example to redirect HTTP to HTTPS:

{
    "return": "301",
    "location": "https://$host$request_uri"
}

When &lt;http://example.com/foo%23bar?baz&gt; is requested, the server
redirects to &lt;https://example.com/foo%23bar?baz&gt;.

===

Testing:

//diff --git a/src/nxt_http_return.c b/src/nxt_http_return.c
//index 82c9156..adeb3a1 100644
//--- a/src/nxt_http_return.c
//+++ b/src/nxt_http_return.c
//@@ -196,6 +196,7 @@ nxt_http_return_send_ready(nxt_task_t *task,
    void *obj, void *data)
//         field-&gt;value = ctx-&gt;encoded.start;
//         field-&gt;value_length = ctx-&gt;encoded.length;
//     }
//+    fprintf(stderr, "ALX: target[%1$i]: &lt;%2$.*1$s&gt;\n",
    (int)r-&gt;target.length, r-&gt;target.start);
//
//     r-&gt;state = &amp;nxt_http_return_send_state;
//

{
	"listeners": {
		"*:81": {
			"pass": "routes/ru"
		}
	},

	"routes": {
		"ru": [{
			"action": {
				"return": 301,
				"location": "$request_uri"
			}
		}]
	}
}

$ curl -i http://localhost:81/*foo%2Abar?baz#arg
HTTP/1.1 301 Moved Permanently
Location: /*foo%2Abar?baz
Server: Unit/1.27.0
Date: Mon, 30 May 2022 16:04:30 GMT
Content-Length: 0

$ sudo cat /usr/local/unit.log | grep ALX
ALX: target[15]: &lt;/*foo%2Abar?baz&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This supports a new variable $request_uri that contains the path
and the query (See RFC 3986, section 3).  Its contents are percent
encoded.  This is useful for example to redirect HTTP to HTTPS:

{
    "return": "301",
    "location": "https://$host$request_uri"
}

When &lt;http://example.com/foo%23bar?baz&gt; is requested, the server
redirects to &lt;https://example.com/foo%23bar?baz&gt;.

===

Testing:

//diff --git a/src/nxt_http_return.c b/src/nxt_http_return.c
//index 82c9156..adeb3a1 100644
//--- a/src/nxt_http_return.c
//+++ b/src/nxt_http_return.c
//@@ -196,6 +196,7 @@ nxt_http_return_send_ready(nxt_task_t *task,
    void *obj, void *data)
//         field-&gt;value = ctx-&gt;encoded.start;
//         field-&gt;value_length = ctx-&gt;encoded.length;
//     }
//+    fprintf(stderr, "ALX: target[%1$i]: &lt;%2$.*1$s&gt;\n",
    (int)r-&gt;target.length, r-&gt;target.start);
//
//     r-&gt;state = &amp;nxt_http_return_send_state;
//

{
	"listeners": {
		"*:81": {
			"pass": "routes/ru"
		}
	},

	"routes": {
		"ru": [{
			"action": {
				"return": 301,
				"location": "$request_uri"
			}
		}]
	}
}

$ curl -i http://localhost:81/*foo%2Abar?baz#arg
HTTP/1.1 301 Moved Permanently
Location: /*foo%2Abar?baz
Server: Unit/1.27.0
Date: Mon, 30 May 2022 16:04:30 GMT
Content-Length: 0

$ sudo cat /usr/local/unit.log | grep ALX
ALX: target[15]: &lt;/*foo%2Abar?baz&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Static: supporting new "index" option.</title>
<updated>2022-05-30T10:42:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2021-12-09T02:00:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=9af5f369511eefea691a5cb6787a31ef3af53a0a'/>
<id>9af5f369511eefea691a5cb6787a31ef3af53a0a</id>
<content type='text'>
This supports a new option "index" that configures a custom index
file name to 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 &lt;example.com/foo/bar/&gt; is requested,
&lt;/www/data/static/foo/bar/lookatthis.html&gt; is served.

Default is "index.html".

===

nxt_conf_validator.c:

Accept "index" as a member of "share", and make sure it's a string.

===

I 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 &lt;index.html&gt; 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."
}
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This supports a new option "index" that configures a custom index
file name to 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 &lt;example.com/foo/bar/&gt; is requested,
&lt;/www/data/static/foo/bar/lookatthis.html&gt; is served.

Default is "index.html".

===

nxt_conf_validator.c:

Accept "index" as a member of "share", and make sure it's a string.

===

I 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 &lt;index.html&gt; 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."
}
</pre>
</div>
</content>
</entry>
<entry>
<title>Static: returning 404 when "index" is a non-regular file.</title>
<updated>2022-05-26T17:31:08+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-02-15T11:30:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=02f50533c4a476b91e4b39a7a2d052095d970983'/>
<id>02f50533c4a476b91e4b39a7a2d052095d970983</id>
<content type='text'>
Before this patch, if "index" was a file, but not a regular file
nor a directory, so it may have been for example a FIFO, Unit
returned 404.  But if "index" was a directory, Unit returned 301.

For consistency, this patch makes Unit return 404 for every
non-regular file, including directories.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before this patch, if "index" was a file, but not a regular file
nor a directory, so it may have been for example a FIFO, Unit
returned 404.  But if "index" was a directory, Unit returned 301.

For consistency, this patch makes Unit return 404 for every
non-regular file, including directories.
</pre>
</div>
</content>
</entry>
<entry>
<title>Added const to remove unnecessary casts.</title>
<updated>2022-05-26T12:11:12+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-05-18T10:49:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=27ca67f0df6c7b606c8496b1c57434032b2a577c'/>
<id>27ca67f0df6c7b606c8496b1c57434032b2a577c</id>
<content type='text'>
Casts are usually very dangerous, disabling most compiler warnings
and basically removing type safety.  This change adds 'const' to a
pointer where we don't need to write, improving type safety, and
that also allows removing some casts.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Casts are usually very dangerous, disabling most compiler warnings
and basically removing type safety.  This change adds 'const' to a
pointer where we don't need to write, improving type safety, and
that also allows removing some casts.
</pre>
</div>
</content>
</entry>
<entry>
<title>HTTP: generalized argument and cookie parsing.</title>
<updated>2022-05-18T13:18:40+00:00</updated>
<author>
<name>Zhidao HONG</name>
<email>z.hong@f5.com</email>
</author>
<published>2022-05-18T13:18:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=6271479610c95d40daf9ed6ec2c7dead67c74f00'/>
<id>6271479610c95d40daf9ed6ec2c7dead67c74f00</id>
<content type='text'>
No functional changes.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
No functional changes.
</pre>
</div>
</content>
</entry>
<entry>
<title>Wrapped debug code in '#if (NXT_DEBUG)'.</title>
<updated>2022-05-17T10:41:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-05-17T10:20:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=7662ec5f1bf27de981a8aa100ab2c5c3fa985269'/>
<id>7662ec5f1bf27de981a8aa100ab2c5c3fa985269</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fixed memcpy(dest, NULL, 0) Undefined Behavior.</title>
<updated>2022-05-17T10:39:41+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-05-17T09:18:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=ba20fa3939c1505866d715a5a1a43f61a4f8de17'/>
<id>ba20fa3939c1505866d715a5a1a43f61a4f8de17</id>
<content type='text'>
nxt_str_null() setted the loc.start pointer to NULL, which was
being passed to memcpy(3) through nxt_debug().  That caused
Undefined Behavior, so we now pass an empty string.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
nxt_str_null() setted the loc.start pointer to NULL, which was
being passed to memcpy(3) through nxt_debug().  That caused
Undefined Behavior, so we now pass an empty string.
</pre>
</div>
</content>
</entry>
<entry>
<title>Supporting empty Location URIs.</title>
<updated>2022-05-16T10:57:37+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-04-09T19:27:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=7066acb2ce438526fb0d60df443320d1c8366760'/>
<id>7066acb2ce438526fb0d60df443320d1c8366760</id>
<content type='text'>
An empty string in Location was being handled specially by not sending a
Location header.  This may occur after variable resolution, so we need to
consider this scenario.

The obsolete RFC 2616 defined the Location header as consisting of an absolute
URI &lt;https://www.rfc-editor.org/rfc/rfc2616#section-14.30&gt;, which cannot be an
empty string.  However, the current RFC 7231 allows the Location to be a
relative URI &lt;https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2&gt;, and a
relative URI may be an empty string &lt;https://stackoverflow.com/a/43338457&gt;.

Due to these considerations, this patch allows sending an empty Location header
without handling this case specially.  This behavior will probably be more
straightforward to users, too.  It also simplifies the code, which is now more
readable, fast, and conformant to the current RFC.  We're skipping an
allocation at request time in a common case such as "action": {"return": 404}
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
An empty string in Location was being handled specially by not sending a
Location header.  This may occur after variable resolution, so we need to
consider this scenario.

The obsolete RFC 2616 defined the Location header as consisting of an absolute
URI &lt;https://www.rfc-editor.org/rfc/rfc2616#section-14.30&gt;, which cannot be an
empty string.  However, the current RFC 7231 allows the Location to be a
relative URI &lt;https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2&gt;, and a
relative URI may be an empty string &lt;https://stackoverflow.com/a/43338457&gt;.

Due to these considerations, this patch allows sending an empty Location header
without handling this case specially.  This behavior will probably be more
straightforward to users, too.  It also simplifies the code, which is now more
readable, fast, and conformant to the current RFC.  We're skipping an
allocation at request time in a common case such as "action": {"return": 404}
</pre>
</div>
</content>
</entry>
</feed>
