summaryrefslogtreecommitdiffhomepage
path: root/src/http (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-09-23QUIC: unbreak client certificate verification after 0d2b2664b41c.Sergey Kandaurov1-0/+2
Initially, client certificate verification didn't work due to the missing hc->ssl on a QUIC stream, which is started to be set in 7738:7f0981be07c4. Then it was lost in 7999:0d2b2664b41c introducing "quic" listen parameter. This change re-adds hc->ssl back for all QUIC connections, similar to SSL.
2020-09-16HTTP/3: rearranged length check when parsing header.Roman Arutyunyan1-5/+5
The new code looks simpler and is similar to other checks.
2020-09-16HTTP/3: removed HTTP/3 parser call from discard body filter.Roman Arutyunyan1-10/+1
Request body discard is disabled for QUIC streams anyway.
2020-09-16HTTP/3: reject HTTP/2 frames.Roman Arutyunyan1-0/+17
As per HTTP/3 draft 30, section 7.2.8: Frame types that were used in HTTP/2 where there is no corresponding HTTP/3 frame have also been reserved (Section 11.2.1). These frame types MUST NOT be sent, and their receipt MUST be treated as a connection error of type H3_FRAME_UNEXPECTED.
2020-09-24SSL: abort handshake on SSL_set_SSL_CTX() errors.Sergey Kandaurov1-1/+4
In rare cases, such as memory allocation failure, SSL_set_SSL_CTX() returns NULL, which could mean that a different SSL configuration has not been set. Note that this new behaviour seemingly originated in OpenSSL-1.1.0 release.
2020-09-23HTTP/2: run posted requests after reading body.Maxim Dounin1-0/+4
HTTP/2 code failed to run posted requests after calling the request body handler, and this resulted in connection hang if a subrequest was created in the body handler and no other actions were made.
2020-09-23HTTP/2: fixed segfault on DATA frames after 400 errors.Maxim Dounin1-0/+7
If 400 errors were redirected to an upstream server using the error_page directive, DATA frames from the client might cause segmentation fault due to null pointer dereference. The bug had appeared in 6989:2c4dbcd6f2e4 (1.13.0). Fix is to skip such frames in ngx_http_v2_state_read_data() (similarly to 7561:9f1f9d6e056a). With the fix, behaviour of 400 errors in HTTP/2 is now similar to one in HTTP/1.x, that is, nginx doesn't try to read the request body. Note that proxying 400 errors, as well as other early stage errors, to upstream servers might not be a good idea anyway. These errors imply that reading and processing of the request (and the request headers) wasn't complete, and proxying of such incomplete request might lead to various errors. Reported by Chenglong Zhang.
2020-09-09Cache: keep c->body_start when Vary changes (ticket #2029).Sergey Kandaurov2-1/+3
If the variant hash doesn't match one we used as a secondary cache key, we switch back to the original key. In this case, c->body_start was kept updated from an existing cache node overwriting the new response value. After file cache update, it led to discrepancy between a cache node and cache file seen as critical errors "file cache .. has too long header".
2020-08-24HTTP/3: skip unknown frames on request stream.Roman Arutyunyan3-11/+60
As per HTTP/3 draft 29, section 4.1: Frames of unknown types (Section 9), including reserved frames (Section 7.2.8) MAY be sent on a request or push stream before, after, or interleaved with other frames described in this section. Also, trailers frame is now used as an indication of the request body end.
2020-09-16HTTP/3: fixed handling request body eof.Roman Arutyunyan3-24/+35
While for HTTP/1 unexpected eof always means an error, for HTTP/3 an eof right after a DATA frame end means the end of the request body. For this reason, since adding HTTP/3 support, eof no longer produced an error right after recv() but was passed to filters which would make a decision. This decision was made in ngx_http_parse_chunked() and ngx_http_v3_parse_request_body() based on the b->last_buf flag. Now that since 0f7f1a509113 (1.19.2) rb->chunked->length is a lower threshold for the expected number of bytes, it can be set to zero to indicate that more bytes may or may not follow. Now it's possible to move the check for eof from parser functions to ngx_http_request_body_chunked_filter() and clean up the parsing code. Also, in the default branch, in case of eof, the following three things happened, which were replaced with returning NGX_ERROR while implementing HTTP/3: - "client prematurely closed connection" message was logged - c->error flag was set - NGX_HTTP_BAD_REQUEST was returned The change brings back this behavior for HTTP/1 as well as HTTP/3.
2020-08-31HTTP/3: do not set the never-indexed literal bit by default.Roman Arutyunyan1-3/+3
The "Literal Header Field Never Indexed" header field representation is not used in HTTP/2, and it makes little sense to make a distinction in HTTP/3.
2020-08-25HTTP/3: drop the unwanted remainder of the request.Roman Arutyunyan2-0/+13
As per HTTP/3 draft 29, section 4.1: When the server does not need to receive the remainder of the request, it MAY abort reading the request stream, send a complete response, and cleanly close the sending part of the stream.
2020-08-20HTTP/3: special handling of client errors in the upstream module.Roman Arutyunyan1-0/+13
The function ngx_http_upstream_check_broken_connection() terminates the HTTP/1 request if client sends eof. For QUIC (including HTTP/3) the c->write->error flag is now checked instead. This flag is set when the entire QUIC connection is closed or STOP_SENDING was received from client.
2020-08-18HTTP/3: request more client body bytes.Roman Arutyunyan1-6/+0
Previously the request body DATA frame header was read by one byte because filters were called only when the requested number of bytes were read. Now, after 08ff2e10ae92 (1.19.2), filters are called after each read. More bytes can be read at once, which simplifies and optimizes the code. This also reduces diff with the default branch.
2020-08-18HTTP/3: fixed context storage in request body parser.Sergey Kandaurov1-1/+1
2020-08-18Merged with the default branch.Roman Arutyunyan6-61/+190
2020-08-10SSL: disabled sending shutdown after ngx_http_test_reading().Maxim Dounin1-0/+6
Sending shutdown when ngx_http_test_reading() detects the connection is closed can result in "SSL_shutdown() failed (SSL: ... bad write retry)" critical log messages if there are blocked writes. Fix is to avoid sending shutdown via the c->ssl->no_send_shutdown flag, similarly to how it is done in ngx_http_keepalive_handler() for kqueue when pending EOF is detected. Reported by Jan Prachaƙ (http://mailman.nginx.org/pipermail/nginx-devel/2018-December/011702.html).
2020-08-10HTTP/2: fixed c->timedout flag on timed out connections.Maxim Dounin1-0/+1
Without the flag, SSL shutdown is attempted on such connections, resulting in useless work and/or bogus "SSL_shutdown() failed (SSL: ... bad write retry)" critical log messages if there are blocked writes.
2020-08-06Request body: optimized handling of small chunks.Maxim Dounin1-0/+25
If there is a previous buffer, copy small chunks into it instead of allocating additional buffer.
2020-08-06Request body: allowed large reads on chunk boundaries.Maxim Dounin1-8/+113
If some additional data from a pipelined request happens to be read into the body buffer, we copy it to r->header_in or allocate an additional large client header buffer for it.
2020-08-06Request body: all read data are now sent to filters.Maxim Dounin1-43/+10
This is a prerequisite for the next change to allow large reads on chunk boundaries.
2020-08-06Added size check to ngx_http_alloc_large_header_buffer().Maxim Dounin1-0/+6
This ensures that copying won't write more than the buffer size even if the buffer comes from hc->free and it is smaller than the large client header buffer size in the virtual host configuration. This might happen if size of large client header buffers is different in name-based virtual hosts, similarly to the problem with number of buffers fixed in 6926:e662cbf1b932.
2020-08-11QUIC: fixed ngx_http_test_reading() for QUIC streams.Roman Arutyunyan1-0/+13
Previously this function generated an error trying to figure out if client shut down the write end of the connection. The reason for this error was that a QUIC stream has no socket descriptor. However checking for eof is not the right thing to do for an HTTP/3 QUIC stream since HTTP/3 clients are expected to shut down the write end of the stream after sending the request. Now the function handles QUIC streams separately. It checks if c->read->error is set. The error flags for c->read and c->write are now set for all streams when closing the QUIC connection instead of setting the pending_eof flag.
2020-07-27FastCGI: fixed zero size buf alerts on extra data (ticket #2018).Maxim Dounin1-6/+22
After 05e42236e95b (1.19.1) responses with extra data might result in zero size buffers being generated and "zero size buf" alerts in writer (if f->rest happened to be 0 when processing additional stdout data).
2020-07-23HTTP/3: server pushes.Roman Arutyunyan7-13/+1020
New directives are added: - http3_max_concurrent_pushes - http3_push - http3_push_preload
2020-07-27QUIC: limited the number of server-initiated streams.Roman Arutyunyan1-13/+15
Also, ngx_quic_create_uni_stream() is replaced with ngx_quic_open_stream() which is capable of creating a bidi stream.
2020-07-22Xslt: disabled ranges.Roman Arutyunyan1-0/+1
Previously, the document generated by the xslt filter was always fully sent to client even if a range was requested and response status was 206 with appropriate Content-Range. The xslt module is unable to serve a range because of suspending the header filter chain. By the moment full response xml is buffered by the xslt filter, range header filter is not called yet, but the range body filter has already been called and did nothing. The fix is to disable ranges by resetting the r->allow_ranges flag much like the image filter that employs a similar technique.
2020-07-14HTTP/3: support $server_protocol variable.Roman Arutyunyan3-4/+6
Now it holds "HTTP/3.0". Previously it was empty.
2020-07-23Style: moved function declarations to match usual code style.Roman Arutyunyan1-11/+9
Plus a few other minor style changes.
2020-07-23HTTP/3: renamed server configuration variables from v3cf to h3scf.Roman Arutyunyan4-26/+26
Now they are similar to HTTP/2 where they are called h2scf.
2020-07-13HTTP/3: renamed ngx_http_v3.c to ngx_http_v3_encode.c.Roman Arutyunyan1-0/+0
The file contains only encoding functions.
2020-07-13HTTP/3: encode frame ids with ngx_http_v3_encode_varlen_int().Roman Arutyunyan1-4/+8
Even though typically frame ids fit into a single byte, calling ngx_http_v3_encode_varlen_int() adds to the code clarity.
2020-07-23HTTP/3: generate Location response header for absolute redirects.Roman Arutyunyan1-2/+81
2020-07-13HTTP/3: header encoding functions.Roman Arutyunyan3-90/+226
2020-07-22HTTP/3: do not call shutdown() for QUIC streams.Roman Arutyunyan1-5/+7
Previously, this triggered an alert "shutdown() failed" in error log.
2020-07-21QUIC: eliminated connection handler argument in ngx_quic_run().Roman Arutyunyan1-1/+1
Now c->listening->handler() is called instead.
2020-07-21QUIC: added "quic" listen parameter in Stream.Roman Arutyunyan1-0/+1
Also, introduced ngx_stream_quic_module.
2020-07-21QUIC: added "quic" listen parameter.Roman Arutyunyan12-379/+540
The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
2020-07-20Fixed format specifiers.Sergey Kandaurov1-1/+1
2020-07-13Merged with the default branch.Sergey Kandaurov13-47/+484
2020-07-09Slice filter: clear original Accept-Ranges.Roman Arutyunyan1-0/+5
The slice filter allows ranges for the response by setting the r->allow_ranges flag, which enables the range filter. If the range was not requested, the range filter adds an Accept-Ranges header to the response to signal the support for ranges. Previously, if an Accept-Ranges header was already present in the first slice response, client received two copies of this header. Now, the slice filter removes the Accept-Ranges header from the response prior to setting the r->allow_ranges flag.
2020-07-06gRPC: generate error when response size is wrong.Maxim Dounin1-1/+38
As long as the "Content-Length" header is given, we now make sure it exactly matches the size of the response. If it doesn't, the response is considered malformed and must not be forwarded (https://tools.ietf.org/html/rfc7540#section-8.1.2.6). While it is not really possible to "not forward" the response which is already being forwarded, we generate an error instead, which is the closest equivalent. Previous behaviour was to pass everything to the client, but this seems to be suboptimal and causes issues (ticket #1695). Also this directly contradicts HTTP/2 specification requirements. Note that the new behaviour for the gRPC proxy is more strict than that applied in other variants of proxying. This is intentional, as HTTP/2 specification requires us to do so, while in other types of proxying malformed responses from backends are well known and historically tolerated.
2020-07-06FastCGI: protection from responses with wrong length.Maxim Dounin3-15/+109
Previous behaviour was to pass everything to the client, but this seems to be suboptimal and causes issues (ticket #1695). Fix is to drop extra data instead, as it naturally happens in most clients. Additionally, we now also issue a warning if the response is too short, and make sure the fact it is truncated is propagated to the client. The u->error flag is introduced to make it possible to propagate the error to the client in case of unbuffered proxying. For responses to HEAD requests there is an exception: we do allow both responses without body and responses with body matching the Content-Length header.
2020-07-06Upstream: drop extra data sent by upstream.Maxim Dounin4-5/+88
Previous behaviour was to pass everything to the client, but this seems to be suboptimal and causes issues (ticket #1695). Fix is to drop extra data instead, as it naturally happens in most clients. This change covers generic buffered and unbuffered filters as used in the scgi and uwsgi modules. Appropriate input filter init handlers are provided by the scgi and uwsgi modules to set corresponding lengths. Note that for responses to HEAD requests there is an exception: we do allow any response length. This is because responses to HEAD requests might be actual full responses, and it is up to nginx to remove the response body. If caching is enabled, only full responses matching the Content-Length header will be cached (see b779728b180c).
2020-07-06Proxy: style.Maxim Dounin1-2/+2
2020-07-06Proxy: detection of data after final chunk.Maxim Dounin1-1/+30
Previously, additional data after final chunk was either ignored (in the same buffer, or during unbuffered proxying) or sent to the client (in the next buffer already if it was already read from the socket). Now additional data are properly detected and ignored in all cases. Additionally, a warning is now logged and keepalive is disabled in the connection.
2020-07-06Proxy: drop extra data sent by upstream.Maxim Dounin1-9/+43
Previous behaviour was to pass everything to the client, but this seems to be suboptimal and causes issues (ticket #1695). Fix is to drop extra data instead, as it naturally happens in most clients.
2020-07-06Memcached: protect from too long responses.Maxim Dounin1-3/+6
If a memcached response was followed by a correct trailer, and then the NUL character followed by some extra data - this was accepted by the trailer checking code. This in turn resulted in ctx->rest underflow and caused negative size buffer on the next reading from the upstream, followed by the "negative size buf in writer" alert. Fix is to always check for too long responses, so a correct trailer cannot be followed by extra data.
2020-07-03HTTP/2: lingering close after GOAWAY.Ruslan Ermilov2-6/+124
After sending the GOAWAY frame, a connection is now closed using the lingering close mechanism. This allows for the reliable delivery of the GOAWAY frames, while also fixing connection resets observed when http2_max_requests is reached (ticket #1250), or with graceful shutdown (ticket #1544), when some additional data from the client is received on a fully closed connection. For HTTP/2, the settings lingering_close, lingering_timeout, and lingering_time are taken from the "server" level.
2020-07-02HTTP/3: simplified handling return codes from parse functions.Roman Arutyunyan1-30/+4