aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_request.h
Commit message (Collapse)AuthorAge
* Added "keepalive_min_timeout" directive.Roman Arutyunyan2025-02-05
| | | | | | | | | | | | | | | | | The directive sets a timeout during which a keepalive connection will not be closed by nginx for connection reuse or graceful shutdown. The change allows clients that send multiple requests over the same connection without delay or with a small delay between them, to avoid receiving a TCP RST in response to one of them. This excludes network issues and non-graceful shutdown. As a side-effect, it also addresses the TCP reset problem described in RFC 9112, Section 9.6, when the last sent HTTP response could be damaged by a followup TCP RST. It is important for non-idempotent requests, which cannot be retried by client. It is not recommended to set keepalive_min_timeout to large values as this can introduce an additional delay during graceful shutdown and may restrict nginx from effective connection reuse.
* Fixed request termination with AIO and subrequests (ticket #2555).Maxim Dounin2024-01-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a request was terminated due to an error via ngx_http_terminate_request() while an AIO operation was running in a subrequest, various issues were observed. This happened because ngx_http_request_finalizer() was only set in the subrequest where ngx_http_terminate_request() was called, but not in the subrequest where the AIO operation was running. After completion of the AIO operation normal processing of the subrequest was resumed, leading to issues. In particular, in case of the upstream module, termination of the request called upstream cleanup, which closed the upstream connection. Attempts to further work with the upstream connection after AIO operation completion resulted in segfaults in ngx_ssl_recv(), "readv() failed (9: Bad file descriptor) while reading upstream" errors, or socket leaks. In ticket #2555, issues were observed with the following configuration with cache background update (with thread writing instrumented to introduce a delay, when a client closes the connection during an update): location = /background-and-aio-write { proxy_pass ... proxy_cache one; proxy_cache_valid 200 1s; proxy_cache_background_update on; proxy_cache_use_stale updating; aio threads; aio_write on; limit_rate 1000; } Similarly, the same issue can be seen with SSI, and can be caused by errors in subrequests, such as in the following configuration (where "/proxy" uses AIO, and "/sleep" returns 444 after some delay, causing request termination): location = /ssi-active-boom { ssi on; ssi_types *; return 200 ' <!--#include virtual="/proxy" --> <!--#include virtual="/sleep" --> '; limit_rate 1000; } Or the same with both AIO operation and the error in non-active subrequests (which needs slightly different handling, see below): location = /ssi-non-active-boom { ssi on; ssi_types *; return 200 ' <!--#include virtual="/static" --> <!--#include virtual="/proxy" --> <!--#include virtual="/sleep" --> '; limit_rate 1000; } Similarly, issues can be observed with just static files. However, with static files potential impact is limited due to timeout safeguards in ngx_http_writer(), and the fact that c->error is set during request termination. In a simple configuration with an AIO operation in the active subrequest, such as in the following configuration, the connection is closed right after completion of the AIO operation anyway, since ngx_http_writer() tries to write to the connection and fails due to c->error set: location = /ssi-active-static-boom { ssi on; ssi_types *; return 200 ' <!--#include virtual="/static-aio" --> <!--#include virtual="/sleep" --> '; limit_rate 1000; } In the following configuration, with an AIO operation in a non-active subrequest, the connection is closed only after send_timeout expires: location = /ssi-non-active-static-boom { ssi on; ssi_types *; return 200 ' <!--#include virtual="/static" --> <!--#include virtual="/static-aio" --> <!--#include virtual="/sleep" --> '; limit_rate 1000; } Fix is to introduce r->main->terminated flag, which is to be checked by AIO event handlers when the r->main->blocked counter is decremented. When the flag is set, handlers are expected to wake up the connection instead of the subrequest (which might be already cleaned up). Additionally, now ngx_http_request_finalizer() is always set in the active subrequest, so waking up the connection properly finalizes the request even if termination happened in a non-active subrequest.
* HTTP: removed unused r->port_start and r->port_end.Vladimir Khomutov2023-11-28
| | | | | | | | Neither r->port_start nor r->port_end were ever used. The r->port_end is set by the parser, though it was never used by the following code (and was never usable, since not copied by the ngx_http_alloc_large_header_buffer() without r->port_start set).
* HTTP/3: postponed session creation to init() callback.Roman Arutyunyan2023-09-14
| | | | | | | | | | | | | | Now the session object is assigned to c->data while ngx_http_connection_t object is referenced by its http_connection field, similar to ngx_http_v2_connection_t and ngx_http_request_t. The change allows to eliminate v3_session field from ngx_http_connection_t. The field was under NGX_HTTP_V3 macro, which was a source of binary compatibility problems when nginx/module is build with/without HTTP/3 support. Postponing is essential since c->data should retain the reference to ngx_http_connection_t object throughout QUIC handshake, because SSL callbacks ngx_http_ssl_servername() and ngx_http_ssl_alpn_select() rely on this.
* Merged with the default branch.Sergey Kandaurov2022-06-22
|\
| * Reworked multi headers to use linked lists.Maxim Dounin2022-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
| * FastCGI: combining headers with identical names (ticket #1724).Maxim Dounin2022-05-30
| | | | | | | | | | | | | | | | | | | | | | | | FastCGI responder is expected to receive CGI/1.1 environment variables in the parameters (see section "6.2 Responder" of the FastCGI specification). Obviously enough, there cannot be multiple environment variables with the same name. Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific Meta-Variables") explicitly requires to combine headers: "If multiple header fields with the same field-name are received then the server MUST rewrite them as a single value having the same semantics".
* | Added r->response_sent flag.Roman Arutyunyan2021-09-30
| | | | | | | | | | | | The flag indicates that the entire response was sent to the socket up to the last_buf flag. The flag is only usable for protocol implementations that call ngx_http_write_filter() from header filter, such as HTTP/1.x and HTTP/3.
* | Merged with the default branch.Sergey Kandaurov2021-09-01
|\|
| * Request body: reading body buffering in filters.Maxim Dounin2021-08-29
| | | | | | | | | | | | | | | | | | | | | | | | | | If a filter wants to buffer the request body during reading (for example, to check an external scanner), it can now do so. To make it possible, the code now checks rb->last_saved (introduced in the previous change) along with rb->rest == 0. Since in HTTP/2 this requires flow control to avoid overflowing the request body buffer, so filters which need buffering have to set the rb->filter_need_buffering flag on the first filter call. (Note that each filter is expected to call the next filter, so all filters will be able set the flag if needed.)
| * Request body: introduced rb->last_saved flag.Maxim Dounin2021-08-29
| | | | | | | | | | | | It indicates that the last buffer was received by the save filter, and can be used to check this at higher levels. To be used in the following changes.
* | Merged with the default branch.Sergey Kandaurov2021-07-15
|\|
| * Disabled spaces in URIs (ticket #196).Maxim Dounin2021-06-28
| | | | | | | | | | | | | | From now on, requests with spaces in URIs are immediately rejected rather than allowed. Spaces were allowed in 31e9677b15a1 (0.8.41) to handle bad clients. It is believed that now this behaviour causes more harm than good.
| * Added CONNECT method rejection.Maxim Dounin2021-06-28
| | | | | | | | | | | | | | | | | | No valid CONNECT requests are expected to appear within nginx, since it is not a forward proxy. Further, request line parsing will reject proper CONNECT requests anyway, since we don't allow authority-form of request-target. On the other hand, RFC 7230 specifies separate message length rules for CONNECT which we don't support, so make sure to always reject CONNECTs to avoid potential abuse.
* | HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.Roman Arutyunyan2021-05-05
| |
* | HTTP/3: reference h3c directly from ngx_http_connection_t.Roman Arutyunyan2021-05-05
| | | | | | | | | | | | | | Previously, an ngx_http_v3_connection_t object was created for HTTP/3 and then assinged to c->data instead of the generic ngx_http_connection_t object. Now a direct reference is added to ngx_http_connection_t, which is less confusing and does not require a flag for http3.
* | HTTP/3: introduced ngx_http_v3_parse_t structure.Roman Arutyunyan2021-02-17
| | | | | | | | | | | | | | | | The structure is used to parse an HTTP/3 request. An object of this type is added to ngx_http_request_t instead of h3_parse generic pointer. Also, the new field is located outside of the request ephemeral zone to keep it safe after request headers are parsed.
* | HTTP/3: refactored request parser.Roman Arutyunyan2021-01-22
| | | | | | | | | | The change reduces diff to the default branch for src/http/ngx_http_request.c and src/http/ngx_http_parse.c.
* | Merged with the default branch.Sergey Kandaurov2020-12-15
|\|
| * Fixed parsing of absolute URIs with empty path (ticket #2079).Maxim Dounin2020-12-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the request line contains request-target in the absolute-URI form, it can contain path-empty instead of a single slash (see RFC 7230, RFC 3986). Previously, the ngx_http_parse_request_line() function only accepted empty path when there was no query string. With this change, non-empty query is also correctly handled. That is, request line "GET http://example.com?foo HTTP/1.1" is accepted and results in $uri "/" and $args "foo". Note that $request_uri remains "?foo", similarly to how spaces in URIs are handled. Providing "/?foo", similarly to how "/" is provided for "GET http://example.com HTTP/1.1", requires allocation.
* | HTTP/3: eliminated r->method_start.Roman Arutyunyan2020-11-25
| | | | | | | | | | | | The field was introduced to ease parsing HTTP/3 requests. The change reduces diff to the default branch.
* | QUIC: added "quic" listen parameter.Roman Arutyunyan2020-07-21
| | | | | | | | | | | | The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
* | Fixed $request_length for HTTP/3.Roman Arutyunyan2020-05-19
| | | | | | | | | | | | | | | | | | New field r->parse_start is introduced to substitute r->request_start and r->header_name_start for request length accounting. These fields only work for this purpose in HTTP/1 because HTTP/1 request line and header line start with these values. Also, error logging is now fixed to output the right part of the request.
* | Refactored HTTP/3 parser.Roman Arutyunyan2020-03-18
| |
* | HTTP/3.Roman Arutyunyan2020-03-13
| |
* | Initial QUIC support in http.Sergey Kandaurov2020-02-28
|/
* Limit conn: $limit_conn_status variable.Roman Arutyunyan2019-11-18
| | | | The variable takes one of the values: PASSED, REJECTED or REJECTED_DRY_RUN.
* Updated comment after 776d1bebdca2.Roman Arutyunyan2019-11-18
|
* Limit req: $limit_req_status variable.Roman Arutyunyan2019-11-06
| | | | | The variable takes one of the values: PASSED, DELAYED, REJECTED, DELAYED_DRY_RUN or REJECTED_DRY_RUN.
* Variables support in limit_rate and limit_rate_after (ticket #293).Ruslan Ermilov2019-04-24
|
* Copy regex unnamed captures to cloned subrequests.Roman Arutyunyan2018-12-11
| | | | | | | | | | | | Previously, unnamed regex captures matched in the parent request, were not available in a cloned subrequest. Now 3 fields related to unnamed captures are copied to a cloned subrequest: r->ncaptures, r->captures and r->captures_data. Since r->captures cannot be changed by either request after creating a clone, a new flag r->realloc_captures is introduced to force reallocation of r->captures. The issue was reported as a proxy_cache_background_update misbehavior in http://mailman.nginx.org/pipermail/nginx/2018-December/057251.html.
* Added r->schema.Ruslan Ermilov2018-06-07
| | | | | For HTTP/1, it keeps scheme from the absolute form of URI. For HTTP/2, the :scheme request pseudo-header field value.
* gRPC: special handling of the TE request header.Maxim Dounin2018-03-17
| | | | | | | | | | | According to the gRPC protocol specification, the "TE" header is used to detect incompatible proxies, and at least grpc-c server rejects requests without "TE: trailers". To preserve the logic, we have to pass "TE: trailers" to the backend if and only if the original request contains "trailers" in the "TE" header. Note that no other TE values are allowed in HTTP/2, so we have to remove anything else.
* Expose more headers with NGX_HTTP_HEADERS.Ruslan Ermilov2018-02-15
|
* Basic support of the Link response header.Ruslan Ermilov2018-02-08
|
* Upstream: keep request body file from removal if requested.Roman Arutyunyan2017-07-19
| | | | | | | | | | The new request flag "preserve_body" indicates that the request body file should not be removed by the upstream module because it may be used later by a subrequest. The flag is set by the SSI (ticket #585), addition and slice modules. Additionally, it is also set by the upstream module when a background cache update subrequest is started to prevent the request body file removal after an internal redirect. Only the main request is now allowed to remove the file.
* Added support for trailers in HTTP responses.Piotr Sikora2017-03-24
| | | | | | | | | | | | | | | | | | | | | | | | | Example: ngx_table_elt_t *h; h = ngx_list_push(&r->headers_out.trailers); if (h == NULL) { return NGX_ERROR; } ngx_str_set(&h->key, "Fun"); ngx_str_set(&h->value, "with trailers"); h->hash = ngx_hash_key_lc(h->key.data, h->key.len); The code above adds "Fun: with trailers" trailer to the response. Modules that want to emit trailers must set r->expect_trailers = 1 in header filter, otherwise they might not be emitted for HTTP/1.1 responses that aren't already chunked. This change also adds $sent_trailer_* variables. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
* Background subrequests for cache updates.Roman Arutyunyan2017-05-25
| | | | | | | | | | Previously, cache background update might not work as expected, making client wait for it to complete before receiving the final part of a stale response. This could happen if the response could not be sent to the client socket in one filter chain call. Now background cache update is done in a background subrequest. This type of subrequest does not block any other subrequests or the main request.
* Don't pretend we support HTTP major versions >1 as HTTP/1.1.Ruslan Ermilov2017-04-25
|
* Added support for the "308 Permanent Redirect" (ticket #877).Simon Leblanc2017-04-11
|
* Added support for "429 Too Many Requests" response (RFC6585).Piotr Sikora2017-03-24
| | | | | | | | This change adds reason phrase in status line and pretty response body when "429" status code is used in "return", "limit_conn_status" and/or "limit_req_status" directives. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
* Converted hc->busy/hc->free to use chain links.Maxim Dounin2017-03-07
| | | | | | | | Most notably, this fixes possible buffer overflows if number of large client header buffers in a virtual server is different from the one in the default server. Reported by Daniil Bondarev.
* Upstream: proxy_cache_background_update and friends.Roman Arutyunyan2017-02-10
| | | | The directives enable cache updates in subrequests.
* Modules compatibility: compatibility with NGX_HTTP_SSL.Maxim Dounin2016-10-10
| | | | | | | With this change it is now possible to load modules compiled without the "--with-http_ssl_module" configure option into nginx binary compiled with it, and vice versa (if a module doesn't use ssl-specific functions), assuming both use the "--with-compat" option.
* Modules compatibility: http2.Maxim Dounin2016-10-03
| | | | | HTTP/2-specific fields in structures are now available unconditionally. Removed NGX_HTTP_V2 from the signature accordingly.
* Modules compatibility: status fields.Maxim Dounin2016-09-29
|
* Modules compatibility: health check fields.Maxim Dounin2016-09-29
|
* Removed influence of some options on structures.Ruslan Ermilov2016-09-20
|
* HTTP/2: the "421 Misdirected Request" response (closes #848).Valentin Bartenev2016-05-20
| | | | | | | | | | | | | | | | | | | | | | | | Since 4fbef397c753 nginx rejects with the 400 error any attempts of requesting different host over the same connection, if the relevant virtual server requires verification of a client certificate. While requesting hosts other than negotiated isn't something legal in HTTP/1.x, the HTTP/2 specification explicitly permits such requests for connection reuse and has introduced a special response code 421. According to RFC 7540 Section 9.1.2 this code can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI. And the client may retry the request over a different connection. Now this code is used for requests that aren't authorized in current connection. After receiving the 421 response a client will be able to open a new connection, provide the required certificate and retry the request. Unfortunately, not all clients currently are able to handle it well. Notably Chrome just shows an error, while at least the latest version of Firefox retries the request over a new connection.
* Dav: return 501 on PUT with ranges (ticket #948).Maxim Dounin2016-05-16
|