summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_route.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-07-26Supporting UNIX sockets in address matching.Alejandro Colomar1-0/+7
This closes #645 issue on GitHub. (Also moved a changelog line that was misplaced in a previous commit.)
2022-07-14Var: dynamic variables support.Zhidao HONG1-5/+9
This commit adds the variables $arg_NAME, $header_NAME, and $cookie_NAME.
2022-06-20Router: forwared header replacement.Zhidao HONG1-3/+2
2022-05-19HTTP: generalized uri encoding.Zhidao HONG1-103/+33
No functional changes.
2022-05-30Static: supporting new "index" option.Alejandro Colomar1-0/+5
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 <example.com/foo/bar/> is requested, </www/data/static/foo/bar/lookatthis.html> 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 <index.html> 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." }
2022-05-18HTTP: generalized argument and cookie parsing.Zhidao HONG1-291/+3
No functional changes.
2022-05-16Supporting empty Location URIs.Alejandro Colomar1-1/+1
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 <https://www.rfc-editor.org/rfc/rfc2616#section-14.30>, which cannot be an empty string. However, the current RFC 7231 allows the Location to be a relative URI <https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2>, and a relative URI may be an empty string <https://stackoverflow.com/a/43338457>. 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}
2022-04-26Fixed indentation.Alejandro Colomar1-2/+2
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 Colomar1-45/+6
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.
2021-11-05Router: matching query string support.Zhidao HONG1-0/+45
The "query" option matches decoded arguments, including plus ('+') to space (' '). Like "uri", it can be a string or an array of strings.
2021-11-05HTTP: removed surplus check for r->args is not NULL.Zhidao HONG1-4/+0
2021-11-05Router: fixed nxt_http_route_arguments_parse().Zhidao HONG1-20/+11
A valid query string argument is a string of "key=value\[&key=value ...\]" pairs with non-empty keys. The fix removes invalid empty arguments.
2021-09-28Static: variables in the "chroot" option.Zhidao HONG1-2/+2
2021-09-07Router: refactored variable pass.Zhidao HONG1-45/+52
Since the "pass" option supports both strings and variables, a generic nxt_var_t structure can be used in the configuration phase, and the "name" field in actions is redundant. No functional changes.
2021-08-12Router: client IP address replacement.Oisin Canty1-8/+4
This commit introduces the replacement of the client address based on the value of a specified HTTP header. This is intended for use when Unit is placed behind a reverse proxy like nginx or a CDN. You must specify the source addresses of the trusted proxies. This can be accomplished with any valid IP pattern supported by Unit's match block: ["10.0.0.1", "10.4.0.0/16", "!192.168.1.1"] The feature is configured per listener. The client address replacement functionality only operates when there is a source IP match and the specified header is present. Typically this would be an 'X-Forwarded-For' header. { "listeners": { "127.0.0.1:8080": { "client_ip": { "header": "X-Forwarded-For", "source": [ "10.0.0.0/8" ] }, "pass": "applications/my_app" }, } } If a request occurs and Unit receives a header like below: "X-Forwarded-For: 84.123.23.23" By default, Unit trusts the last rightmost IP in the header, so REMOTE_ADDR will be set to 84.123.23.23 if the connection originated from 10.0.0.0/8. If Unit runs behind consecutive reverse proxies and receives a header similar to the following: "X-Forwarded-For: 84.123.23.23, 10.0.0.254" You will need to enable "recursive" checking, which walks the header from last address to first and chooses the first non-trusted address it finds. { "listeners": { "127.0.0.1:8080": { "client_ip": { "header": "X-Forwarded-For", "source": [ "10.0.0.0/8" ] "recursive": true, }, "pass": "applications/my_app" }, } } If a connection from 10.0.0.0/8 occurs, the chain is walked. Here, 10.0.0.254 is also a trusted address so the client address will be replaced with 84.123.23.23. If all IP addresses in the header are trusted, the client address is set to the first address in the header: If 10.0.0.0/8 is trusted and "X-Forwarded-For: 10.0.0.3, 10.0.0.2, 10.0.0.1", the client address will be replaced with 10.0.0.3.
2021-08-05Router: fixed crash when matching an empty address pattern array.Oisin Canty1-0/+5
A crash would occur when the router tried to match an against an empty address pattern array. The following configuration was used to reproduce the issue: { "listeners": { "127.0.0.1:8082": { "pass": "routes" } }, "routes": [ { "match": { "source": [] }, "action": { "return": 200 } } ] }
2021-08-02Router: fixed segmentation fault.Zhidao HONG1-0/+4
In the case that routes or upstreams is empty and the pass option is a variable. If the resolved pass is routes or upstreams, a segment error occurred.
2021-07-24Router: split nxt_http_app_conf_t from nxt_http_action_t.Zhidao HONG1-23/+3
No functional changes.
2021-07-26Router: renamed nxt_http_proxy_create() as nxt_http_proxy_init().Zhidao HONG1-10/+2
No functional changes.
2021-07-23Router: split nxt_http_static_conf_t from nxt_http_action_t.Zhidao HONG1-84/+17
No functional changes.
2021-05-24Router: split nxt_http_return_conf_t from nxt_http_action_t.Zhidao HONG1-87/+43
No functional changes.
2021-05-06Static: implemented MIME filteringOisin Canty1-12/+29
2021-04-29Static: support for openat2() features.Zhidao HONG1-1/+62
Support for chrooting, rejecting symlinks, and rejecting crossing mounting points on a per-request basis during static file serving.
2021-04-22Router: grouped app and share fields in nxt_http_action_t.Zhidao HONG1-19/+27
This is a prerequisite for further introduction of openat2() features. No functional changes.
2021-02-01Fixed building by GCC 10 with -flto and -O2.Valentin Bartenev1-0/+6
This closes #467 issue on GitHub.
2020-11-17Router: matching regular expressions support.Axel Duch1-13/+86
2020-10-07Router: fixed "not empty" pattern matching.Valentin Bartenev1-4/+0
The "!" pattern should be opposite to "", i.e. match only non-empty values. But after 3c00af54b937 it was equal to "!*", which is wrong.
2020-08-28Router: fixed "pass" to upstreams.hongzhidao1-1/+5
Messed up return values in nxt_upstream_find() caused error in applying any configuration with a valid "pass" value in router configuration pointing to upstream. That wasn't the case in "listeners" objects, where the return value wasn't checked. Also, it caused segfault in cases where the "pass" option was configured with variables and resulting value was pointing to a non-existent upstream. Added missing return checks as well to catch possible memory allocation errors. The bug was introduced in d32bc428f46b. This closes #472 issue on GitHub.
2020-08-13Fixed typo in return value check.Valentin Bartenev1-1/+1
Found by Coverity (CID 361277).
2020-08-13Basic variables support.Valentin Bartenev1-71/+136
2020-07-24Minor changes and renaming an NJS artifact to NXT.Axel Duch1-3/+3
This is partially related to #434 issue on Github. Thanks to 洪志道 (Hong Zhi Dao).
2020-07-10Router: route patterns multi wildcards fix.Axel Duch1-3/+6
Matching 'start' and 'end' position now adjusted to avoid false matching. This is related to #434 issue on Github. Thanks to 洪志道 (Hong Zhi Dao).
2020-07-04Router: route patterns multi wildcards support.Axel Duch1-113/+205
2020-05-15Router: removed two unused assignments.Valentin Bartenev1-3/+0
This should resolve some static analyzers warnings.
2020-05-14Router: decode uri and args.Axel Duch1-57/+221
2020-05-14PHP: implemented "targets" option.Valentin Bartenev1-3/+18
This allows to specify multiple subsequent targets inside PHP applications. For example: { "listeners": { "*:80": { "pass": "routes" } }, "routes": [ { "match": { "uri": "/info" }, "action": { "pass": "applications/my_app/phpinfo" } }, { "match": { "uri": "/hello" }, "action": { "pass": "applications/my_app/hello" } }, { "action": { "pass": "applications/my_app/rest" } } ], "applications": { "my_app": { "type": "php", "targets": { "phpinfo": { "script": "phpinfo.php", "root": "/www/data/admin", }, "hello": { "script": "hello.php", "root": "/www/data/test", }, "rest": { "root": "/www/data/example.com", "index": "index.php" }, } } } }
2020-05-14Configuration: URI encoding in the "pass" option.Valentin Bartenev1-29/+83
This is useful to escape "/" in path fragments. For example, in order to reference the application named "foo/bar": { "pass": "applications/foo%2Fbar" }
2020-03-30Configuration: support for rational numbers.Valentin Bartenev1-1/+1
2020-03-21Implemented "location" option for "return" action.Valentin Bartenev1-2/+36
This allows to specify redirects: { "action": { "return": 301, "location": "https://www.example.com/" } }
2020-03-27Implemented "return" action.Valentin Bartenev1-0/+12
The "return" action can be used to immediately generate a simple HTTP response with an arbitrary status: { "action": { "return": 404 } } This is especially useful for denying access to specific resources.
2020-03-27Initialization of the action object made more consistent.Valentin Bartenev1-3/+3
2020-03-06Round robin upstream added.Igor Sysoev1-0/+6
2020-03-04Refactored nxt_http_action.Igor Sysoev1-16/+12
2020-03-11Fixed negative patterns combined with address rules.Axel Duch1-6/+40
2020-03-03Added a "fallback" option to be used with the "share" action.Valentin Bartenev1-23/+49
It allows proceeding to another action if a file isn't available. An example: { "share": "/data/www/", "fallback": { "pass": "applications/php" } } In the example above, an attempt is made first to serve a request with a file from the "/data/www/" directory. If there's no such file, the request is passed to the "php" application. Fallback actions may be nested: { "share": "/data/www/", "fallback": { "share": "/data/cache/", "fallback": { "proxy": "http://127.0.0.1:9000" } } }
2019-12-24Router: introducing routing on listener address.Axel Duch1-4/+31
2019-12-24Router: introducing routing on client address.Axel Duch1-4/+239
2019-11-14Initial proxy support.Igor Sysoev1-2/+18
2019-11-14Replacing pass with action.Igor Sysoev1-71/+123
2019-09-19Basic support for serving static files.Valentin Bartenev1-8/+20