summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_request.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
4 daysotel: add header parsing and test call stateAva Hahn1-0/+4
Enables Unit to parse the tracestate and traceparent headers and add it to the list, as well as calls to nxt_otel_test_and_call_state. Signed-off-by: Ava Hahn <a.hahn@f5.com> Signed-off-by: Gabor Javorszky <g.javorszky@f5.com>
4 daysotel: add build tooling to include otel codeAva Hahn1-0/+11
Adds the --otel flag to the configure command and the various build time variables and checks that are needed in this flow. It also includes the nxt_otel.c and nxt_otel.h files that are needed for the rest of Unit to talk to the compiled static library that's generated from the rust crate. Signed-off-by: Ava Hahn <a.hahn@f5.com> Co-authored-by: Gabor Javorszky <g.javorszky@f5.com> Signed-off-by: Gabor Javorszky <g.javorszky@f5.com>
2024-08-20http: Get rid of nxt_http_request_access_log()Zhidao HONG1-22/+5
2024-08-20http: Refactor out nxt_tstr_cond_t from the access log moduleZhidao HONG1-34/+46
This nxt_tstr_cond_t will be reused for the feature of adding "if" option to the "match" object. The two "if" options have the same usage.
2024-08-20var: Restrict nxt_tstr_query() to only support synchronous operationZhidao HONG1-3/+2
Initially, variable query was designed to accomodate both synchronous and asynchronous operations. However, upon consideration of actual requirements, we recognized that asynchronous support was not needed. The refactoring ensures that the success or failure of the variable query operation is now directly indicated by its return value. This change streamlines the function's usage and enhances code clarity, as it facilitates immediate error handling without the need for asynchronous callbacks or additional error checking functions. Note the patch only works for Unit native variables but not njs variables.
2024-06-20http: Support chunked request bodiesZhidao HONG1-0/+43
This is a temporary support for chunked request bodies by converting to Content-Length. This allows for processing of such requests until a more permanent solution is developed. A new configuration option "chunked_transform" has been added to enable this feature. The option can be set as follows: { "settings": { "chunked_transform": true } } By default, this option is set to false, which retains the current behaviour of rejecting chunked requests with a '411 Length Required' status code. Please note that this is an experimental implementation. Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
2024-03-11Avoiding arithmetic ops with NULL pointer in nxt_http_arguments_parseAndrei Zeliankou1-0/+6
Can be reproduced by test/test_variables.py::test_variables_dynamic_arguments with enabled UndefinedBehaviorSanitizer: src/nxt_http_request.c:961:17: runtime error: applying zero offset to null pointer #0 0x1050d95a4 in nxt_http_arguments_parse nxt_http_request.c:961 #1 0x105102bf8 in nxt_http_var_arg nxt_http_variables.c:621 #2 0x104f95d74 in nxt_var_interpreter nxt_var.c:507 #3 0x104f98c98 in nxt_tstr_query nxt_tstr.c:265 #4 0x1050abfd8 in nxt_router_access_log_writer nxt_router_access_log.c:194 #5 0x1050d81f4 in nxt_http_request_close_handler nxt_http_request.c:838 #6 0x104fcdc48 in nxt_event_engine_start nxt_event_engine.c:542 #7 0x104fba838 in nxt_thread_trampoline nxt_thread.c:126 #8 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030) #9 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_request.c:961:17 Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
2024-01-29HTTP: enhanced access log with conditional filtering.Zhidao HONG1-6/+48
This feature allows users to specify conditions to control if access log should be recorded. The "if" option supports a string and JavaScript code. If its value is empty, 0, false, null, or undefined, the logs will not be recorded. And the '!' as a prefix inverses the condition. Example 1: Only log requests that sent a session cookie. { "access_log": { "if": "$cookie_session", "path": "..." } } Example 2: Do not log health check requests. { "access_log": { "if": "`${uri == '/health' ? false : true}`", "path": "..." } } Example 3: Only log requests when the time is before 22:00. { "access_log": { "if": "`${new Date().getHours() < 22}`", "path": "..." } } or { "access_log": { "if": "!`${new Date().getHours() >= 22}`", "path": "..." } } Closes: https://github.com/nginx/unit/issues/594
2024-01-29HTTP: refactored out nxt_http_request_access_log().Zhidao HONG1-7/+18
This is in preparation for adding conditional access logging. No functional changes.
2023-08-09HTTP: controlling response headers support.Zhidao HONG1-0/+6
2023-08-09HTTP: stored matched action in nxt_http_request_t.Zhidao HONG1-5/+3
No functional changes.
2023-04-20HTTP: added basic URI rewrite.Zhidao HONG1-0/+9
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-25Allow to remove the version string in HTTP responses.Andrew Clayton1-3/+9
Normally Unit responds to HTTP requests by including a header like Server: Unit/1.30.0 however it can sometimes be beneficial to withhold the version information and in this case just respond with Server: Unit This patch adds a new "settings.http" boolean option called server_version, which defaults to true, in which case the full version information is sent. However this can be set to false, e.g "settings": { "http": { "server_version": false } }, in which case Unit responds without the version information as the latter example above shows. Link: <https://www.ietf.org/rfc/rfc9110.html#section-10.2.4> Closes: <https://github.com/nginx/unit/issues/158> Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-01-30NJS: adding the missing vm destruction.Zhidao HONG1-0/+4
This commit fixed the njs memory leak happened in the config validation, updating and http requests.
2022-11-20Basic njs support.Zhidao HONG1-1/+1
2022-11-20Var: separating nxt_tstr_t from nxt_var_t.Zhidao HONG1-1/+3
It's for the introduction of njs support. For each option that supports native variable and JS template literals introduced next, it's unified as template string. No functional changes.
2022-10-12HTTP: added a $request_time variable.Zhidao HONG1-0/+2
2022-09-19HTTP: fixed cookie parsing.Zhidao HONG1-5/+2
The fixing supports the cookie value with the '=' character. This is related to #756 PR on Github. Thanks to changxiaocui.
2022-08-29Status: added requests count.Zhidao HONG1-0/+2
2022-07-28Log: customizable access log format.Zhidao HONG1-3/+6
2022-07-14Var: dynamic variables support.Zhidao HONG1-0/+54
This commit adds the variables $arg_NAME, $header_NAME, and $cookie_NAME.
2022-06-22Constified numerous function parameters.Andrew Clayton1-6/+6
As was pointed out by the cppcheck[0] static code analysis utility we can mark numerous function parameters as 'const'. This acts as a hint to the compiler about our intentions and the compiler will tell us when we deviate from them. [0]: https://cppcheck.sourceforge.io/
2022-06-20Router: forwared header replacement.Zhidao HONG1-40/+111
2022-06-20Router: introduced nxt_http_forward_t.Zhidao HONG1-14/+16
This makes the replacement of forwarded request header like client_ip and protocol more generic. It's a prerequirement for protocol replacement. No functional changes.
2022-05-19HTTP: generalized uri encoding.Zhidao HONG1-0/+83
No functional changes.
2022-05-18HTTP: generalized argument and cookie parsing.Zhidao HONG1-0/+276
No functional changes.
2021-09-07Router: refactored variable pass.Zhidao HONG1-2/+0
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-0/+150
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-07-24Router: split nxt_http_app_conf_t from nxt_http_action_t.Zhidao HONG1-3/+1
No functional changes.
2021-04-22Router: grouped app and share fields in nxt_http_action_t.Zhidao HONG1-2/+2
This is a prerequisite for further introduction of openat2() features. No functional changes.
2020-10-26Increased request memory pool size.Valentin Bartenev1-1/+1
Previous value was too small, which reduced efficiency of the pool causing a lot of additional allocations even for simple request and response.
2020-08-13Basic variables support.Valentin Bartenev1-4/+11
2020-05-14PHP: implemented "targets" option.Valentin Bartenev1-0/+2
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-04-16Using malloc/free for the http fields hash.Max Romanov1-3/+3
This is required due to lack of a graceful shutdown: there is a small gap between the runtime's memory pool release and router process's exit. Thus, a worker thread may start processing a request between these two operations, which may result in an http fields hash access and subsequent crash. To simplify issue reproduction, it makes sense to add a 2 sec sleep before exit() in nxt_runtime_exit().
2020-03-12Using disk file to store large request body.Max Romanov1-0/+8
This closes #386 on GitHub.
2020-03-12Moving request memory pool retain call after RPC data allocation.Max Romanov1-10/+0
If the call is done only after a successful RPC data allocation, its corresponding release call is not missed, which avoids a potential leak.
2020-03-12Checking Content-Length value right after header parse.Max Romanov1-1/+8
The check was moved from the request body read stage.
2019-11-14Initial proxy support.Igor Sysoev1-2/+2
2019-11-14Introduced chained buffer completion handlers.Igor Sysoev1-3/+8
2019-11-14Using request task.Igor Sysoev1-2/+2
2019-11-14Replacing pass with action.Igor Sysoev1-15/+15
2019-09-19Basic support for serving static files.Valentin Bartenev1-17/+8
2019-08-26Adding body handler to nxt_http_request_header_send().Igor Sysoev1-2/+3
2019-08-20Introducing websocket support in router and libunit.Max Romanov1-6/+15
2019-08-06Refactored HTTP protocol callback table.Igor Sysoev1-14/+14
2019-07-24Added routing based on request scheme.Axel Duch1-1/+0
Scheme matches exact string “http” or “https”.
2019-05-30Handling routing errors.Igor Sysoev1-15/+12
2019-03-21Adjusting request schema value according to connection tls state.Max Romanov1-6/+9
This closes #223 issue on GitHub.
2019-03-18Setting request error flag in error handler.Max Romanov1-0/+2
Absence of this flag is the reason of memory leak in case when client disconnected before receiving all response data.
2019-03-06Removed unnecessary abstraction layer.Alexander Borisov1-74/+8