summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_request.h (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-06-19Upstream: early hints support.Roman Arutyunyan1-0/+1
The change implements processing upstream early hints response in ngx_http_proxy_module and ngx_http_grpc_module. A new directive "early_hints" enables sending early hints to the client. By default, sending early hints is disabled. Example: map $http_sec_fetch_mode $early_hints { navigate $http2$http3; } early_hints $early_hints; proxy_pass http://example.com;
2025-02-05Added "keepalive_min_timeout" directive.Roman Arutyunyan1-0/+2
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.
2024-01-30Fixed request termination with AIO and subrequests (ticket #2555).Maxim Dounin1-0/+1
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.
2023-11-28HTTP: removed unused r->port_start and r->port_end.Vladimir Khomutov1-2/+0
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).
2023-09-14HTTP/3: postponed session creation to init() callback.Roman Arutyunyan1-4/+0
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.
2022-06-22Merged with the default branch.Sergey Kandaurov1-6/+8
2022-05-30Reworked multi headers to use linked lists.Maxim Dounin1-6/+6
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.
2022-05-30FastCGI: combining headers with identical names (ticket #1724).Maxim Dounin1-0/+2
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".
2021-09-30Added r->response_sent flag.Roman Arutyunyan1-0/+1
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.
2021-09-01Merged with the default branch.Sergey Kandaurov1-0/+3
2021-08-29Request body: reading body buffering in filters.Maxim Dounin1-0/+2
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.)
2021-08-29Request body: introduced rb->last_saved flag.Maxim Dounin1-0/+1
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.
2021-07-15Merged with the default branch.Sergey Kandaurov1-19/+17
2021-06-28Disabled spaces in URIs (ticket #196).Maxim Dounin1-3/+0
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.
2021-06-28Added CONNECT method rejection.Maxim Dounin1-16/+17
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.
2021-05-05HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.Roman Arutyunyan1-1/+1
2021-05-05HTTP/3: reference h3c directly from ngx_http_connection_t.Roman Arutyunyan1-1/+4
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.
2021-02-17HTTP/3: introduced ngx_http_v3_parse_t structure.Roman Arutyunyan1-4/+1
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.
2021-01-22HTTP/3: refactored request parser.Roman Arutyunyan1-1/+1
The change reduces diff to the default branch for src/http/ngx_http_request.c and src/http/ngx_http_parse.c.
2020-12-15Merged with the default branch.Sergey Kandaurov1-0/+3
2020-12-10Fixed parsing of absolute URIs with empty path (ticket #2079).Maxim Dounin1-0/+3
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.
2020-11-25HTTP/3: eliminated r->method_start.Roman Arutyunyan1-1/+0
The field was introduced to ease parsing HTTP/3 requests. The change reduces diff to the default branch.
2020-07-21QUIC: added "quic" listen parameter.Roman Arutyunyan1-1/+0
The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
2020-05-19Fixed $request_length for HTTP/3.Roman Arutyunyan1-0/+1
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.
2020-03-18Refactored HTTP/3 parser.Roman Arutyunyan1-8/+1
2020-03-13HTTP/3.Roman Arutyunyan1-0/+13
2020-02-28Initial QUIC support in http.Sergey Kandaurov1-0/+1
2019-11-18Limit conn: $limit_conn_status variable.Roman Arutyunyan1-1/+1
The variable takes one of the values: PASSED, REJECTED or REJECTED_DRY_RUN.
2019-11-18Updated comment after 776d1bebdca2.Roman Arutyunyan1-1/+1
2019-11-06Limit req: $limit_req_status variable.Roman Arutyunyan1-1/+1
The variable takes one of the values: PASSED, DELAYED, REJECTED, DELAYED_DRY_RUN or REJECTED_DRY_RUN.
2019-04-24Variables support in limit_rate and limit_rate_after (ticket #293).Ruslan Ermilov1-0/+3
2018-12-11Copy regex unnamed captures to cloned subrequests.Roman Arutyunyan1-0/+4
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.
2018-06-07Added r->schema.Ruslan Ermilov1-0/+1
For HTTP/1, it keeps scheme from the absolute form of URI. For HTTP/2, the :scheme request pseudo-header field value.
2018-03-17gRPC: special handling of the TE request header.Maxim Dounin1-0/+1
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.
2018-02-15Expose more headers with NGX_HTTP_HEADERS.Ruslan Ermilov1-1/+1
2018-02-08Basic support of the Link response header.Ruslan Ermilov1-0/+1
2017-07-19Upstream: keep request body file from removal if requested.Roman Arutyunyan1-0/+1
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.
2017-03-24Added support for trailers in HTTP responses.Piotr Sikora1-0/+2
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>
2017-05-25Background subrequests for cache updates.Roman Arutyunyan1-1/+2
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.
2017-04-25Don't pretend we support HTTP major versions >1 as HTTP/1.1.Ruslan Ermilov1-2/+4
2017-04-11Added support for the "308 Permanent Redirect" (ticket #877).Simon Leblanc1-0/+1
2017-03-24Added support for "429 Too Many Requests" response (RFC6585).Piotr Sikora1-0/+1
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>
2017-03-07Converted hc->busy/hc->free to use chain links.Maxim Dounin1-3/+2
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.
2017-02-10Upstream: proxy_cache_background_update and friends.Roman Arutyunyan1-1/+4
The directives enable cache updates in subrequests.
2016-10-10Modules compatibility: compatibility with NGX_HTTP_SSL.Maxim Dounin1-3/+1
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.
2016-10-03Modules compatibility: http2.Maxim Dounin1-4/+0
HTTP/2-specific fields in structures are now available unconditionally. Removed NGX_HTTP_V2 from the signature accordingly.
2016-09-29Modules compatibility: status fields.Maxim Dounin1-0/+1
2016-09-29Modules compatibility: health check fields.Maxim Dounin1-0/+2
2016-09-20Removed influence of some options on structures.Ruslan Ermilov1-4/+1
2016-05-20HTTP/2: the "421 Misdirected Request" response (closes #848).Valentin Bartenev1-0/+1
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.