unit
unit copied to clipboard
Supporting new "index" option.
This contains several patch sets in itself, but it's too complex for github pull requests. The breakdown is:
Variables:
93371e9 (gh/index-var, alx/index-var, index-var) Tests: added tests for "index" (var) option.
a3532c9 Static: supporting variables in the "index" option.
5642e81 Generalized code.
Simple string:
2506eba (gh/index-str, alx/index-str, index-str) Tests: added tests for "index" (string) option.
53e4662 Static: supporting new "index" option.
Some cleanup and minor fixes before the patch set itself (already merged):
bc4990a (gh/ret404, alx/ret404, ret404) Static: returning 404 when "index" is a non-regular file.
1b5ce9c (gh/rename, alx/rename, rename) Renamed nxt_http_static_ctx_t field 'index' to 'share_idx'.
I removed the implementation of index as an array. As suggested by @hongzhidao, I'm not sure we need it.
https://github.com/nginx/unit/pull/684#discussion_r872368368
I'll keep the code in a branch in my personal repository, in case we need it in the future.
If someone requests the feature in the future, we can always reconsider it; but let's keep it simple while we're unsure.
I removed the implementation of
indexas an array. As suggested by @hongzhidao, I'm not sure we need it. #684 (comment)I'll keep the code in a branch in my personal repository, in case we need it in the future.
If someone requests the feature in the future, we can always reconsider it; but let's keep it simple while we're unsure.
Makes sense.
I removed the implementation of
indexas an array. As suggested by @hongzhidao, I'm not sure we need it. #684 (comment)I'll keep the code in a branch in my personal repository, in case we need it in the future.
If someone requests the feature in the future, we can always reconsider it; but let's keep it simple while we're unsure.
Note that if there is only one single index, it should be resolved only once if it's a variable string.
For the first patch set (index-str; constant index string), I tested the following config, which works both with and without --debug:
{
"listeners": {
"*:80": { "pass": "routes/idx-html" },
"*:81": { "pass": "routes/idx" },
"*:82": { "pass": "routes/empty" },
"*:83": { "pass": "routes/no-idx" },
"*:84": { "pass": "routes/dir" },
"*:85": { "pass": "routes/dir-slash" },
"*:86": { "pass": "routes/no-slash-share" },
"*:87": { "pass": "routes/share" },
"*:88": { "pass": "routes/uri" }
},
"routes": {
"idx-html": [{
"action": {"share": "/home/alx/srv/www/", "index": "readme.html"}
}],
"idx": [{
"action": {"share": "/home/alx/srv/www/", "index": "readme"}
}],
"empty": [{
"action": {"share": "/home/alx/srv/www/", "index": ""}
}],
"no-idx": [{
"action": {"share": "/home/alx/srv/www/"}
}],
"dir": [{
"action": {"share": "/home/alx/srv/www/", "index": "dir"}
}],
"dir-slash": [{
"action": {"share": "/home/alx/srv/www/", "index": "dir/"}
}],
"no-slash-share": [{
"action": {"share": "/home/alx/srv/www", "index": "readme.html"}
}],
"share": [{
"action": {"share": "/home/alx/srv/www/readme"}
}],
"uri": [{
"action": {"share": "/home/alx/srv/www$uri", "index": "readme.html"}
}]
}
}
With the following results:
$ seq 80 88 \
| while read p; do
url="localhost:$p";
echo "URL: $url";
curl $url;
echo;
done;
URL: localhost:80
rdmh
URL: localhost:81
rdm
URL: localhost:82
<!DOCTYPE html><title>Error 404</title><p>Error 404.
URL: localhost:83
idx
URL: localhost:84
<!DOCTYPE html><title>Error 404</title><p>Error 404.
URL: localhost:85
<!DOCTYPE html><title>Error 404</title><p>Error 404.
URL: localhost:86
URL: localhost:87
rdm
URL: localhost:88
rdmh
$ curl -i localhost:86
HTTP/1.1 301 Moved Permanently
Location: //
Server: Unit/1.27.0
Date: Thu, 26 May 2022 17:08:30 GMT
Content-Length: 0
I already merged the following:
(ret404) Static: returning 404 when "index" is a non-regular file.
(rename) Renamed nxt_http_static_ctx_t field 'index' to 'share_idx'.
Also merged:
(index-str) Tests: added tests for "index" (string) option.
Static: supporting new "index" option.
We don't intend to add more of this feature for now. I'm closing this. If we ever want it, let's reopen it then.