summaryrefslogtreecommitdiffhomepage
path: root/src/http/v2 (follow)
AgeCommit message (Collapse)AuthorFilesLines
2017-08-01Variables: macros for null variables.Ruslan Ermilov1-1/+1
No functional changes.
2017-03-24HTTP/2: added support for trailers in HTTP responses.Piotr Sikora1-14/+152
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-13HTTP/2: reject HTTP/2 requests without ":scheme" pseudo-header.Piotr Sikora1-0/+1
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-02HTTP/2: don't send SETTINGS ACK before already queued DATA frames.Piotr Sikora2-1/+10
Previously, SETTINGS ACK was sent immediately upon receipt of SETTINGS frame, before already queued DATA frames created using old SETTINGS. This incorrect behavior was source of interoperability issues, because peers rely on the fact that new SETTINGS are in effect after receiving SETTINGS ACK. Reported by Feng Li. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-02HTTP/2: make SETTINGS ACK frame reusable.Piotr Sikora1-25/+31
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-02HTTP/2: send SETTINGS ACK after applying all SETTINGS params.Piotr Sikora1-2/+2
This avoids sending unnecessary SETTINGS ACK in case of PROTOCOL_ERROR. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-02HTTP/2: emit new frames only after applying all SETTINGS params.Piotr Sikora1-6/+11
Previously, new frames could be emitted in the middle of applying new (and already acknowledged) SETTINGS params, which is illegal. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-05-30HTTP/2: add debug logging of pseudo-headers and cookies.Piotr Sikora1-20/+28
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-05-26Introduced ngx_tcp_nodelay().Ruslan Ermilov1-23/+2
2017-05-23HTTP/2: fixed segfault when memory allocation failed.Valentin Bartenev1-2/+2
If allocation of cleanup handler in the HTTP/2 header filter failed, then a stream might be freed with a HEADERS frame left in the output queue. Now the HEADERS frame is accounted in the queue before trying to allocate the cleanup handler.
2017-04-24HTTP/2: reduced difference to HTTP/1.x in reading request body.Valentin Bartenev2-25/+6
Particularly, this eliminates difference in behavior for requests without body and deduplicates code. Prodded by Piotr Sikora.
2017-04-24HTTP/2: rejecting zero WINDOW_UPDATE with PROTOCOL_ERROR.Valentin Bartenev1-0/+38
It's required by RFC 7540. While there is no real harm from such frames, that should help to detect broken clients. Based on a patch by Piotr Sikora.
2017-03-26HTTP/2: style and typos.Piotr Sikora2-7/+8
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-29HTTP/2: fixed connection finalization.Valentin Bartenev1-3/+8
All streams in connection must be finalized before the connection itself can be finalized and all related memory is freed. That's not always possible on the current event loop iteration. Thus when the last stream is finalized, it sets the special read event handler ngx_http_v2_handle_connection_handler() and posts the event. Previously, this handler didn't check the connection state and could call the regular event handler on a connection that was already in finalization stage. In the worst case that could lead to a segmentation fault, since some data structures aren't supposed to be used during connection finalization. Particularly, the waiting queue can contain already freed streams, so the WINDOW_UPDATE frame received by that moment could trigger accessing to these freed streams. Now, the connection error flag is explicitly checked in ngx_http_v2_handle_connection_handler().
2017-03-29HTTP/2: fixed stream finalization.Valentin Bartenev1-0/+3
In order to finalize stream the error flag is set on fake connection and either "write" or "read" event handler is called. The read events of fake connections are always ready, but it's not the case with the write events. When the ready flag isn't set, the error flag can be not checked in some cases and as a result stream isn't finalized. Now the ready flag is explicilty set on write events for proper finalization in all cases.
2017-03-26HTTP/2: emit PROTOCOL_ERROR on padding errors.Piotr Sikora1-2/+4
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-26HTTP/2: fix flow control with padded DATA frames.Piotr Sikora1-10/+12
Previously, flow control didn't account for padding in DATA frames, which meant that its view of the world could drift from peer's view by up to 256 bytes per received padded DATA frame, which could lead to a deadlock. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-26HTTP/2: fix $body_bytes_sent variable.Piotr Sikora1-0/+3
Previously, its value included payloads and frame headers of HEADERS and CONTINUATION frames. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-26HTTP/2: fix $bytes_sent variable.Piotr Sikora1-0/+2
Previously, its value accounted for payloads of HEADERS, CONTINUATION and DATA frames, as well as frame headers of HEADERS and DATA frames, but it didn't account for frame headers of CONTINUATION frames. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-01-31Implemented the "server_tokens build" option.Ruslan Ermilov1-5/+40
Based on a patch by Tom Thorogood.
2016-12-21Core: relative redirects (closes #1000).Ruslan Ermilov1-1/+3
The current version of HTTP/1.1 standard allows relative references in redirects (https://tools.ietf.org/html/rfc7231#section-7.1.2). Allow this form for redirects generated by nginx by introducing the new directive absolute_redirect.
2016-12-10HTTP/2: prevented creating temp files for requests without body.Valentin Bartenev1-2/+4
The problem was introduced by 52bd8cc17f34.
2016-11-28HTTP/2: fixed posted streams handling.Valentin Bartenev3-38/+42
A bug was introduced by 82efcedb310b that could lead to timing out of responses or segmentation fault, when accept_mutex was enabled. The output queue in HTTP/2 can contain frames from different streams. When the queue is sent, all related write handlers need to be called. In order to do so, the streams were added to the h2c->posted queue after handling sent frames. Then this queue was processed in ngx_http_v2_write_handler(). If accept_mutex is enabled, the event's "ready" flag is set but its handler is not called immediately. Instead, the event is added to the ngx_posted_events queue. At the same time in this queue can be events from upstream connections. Such events can result in sending output queue before ngx_http_v2_write_handler() is triggered. And at the time ngx_http_v2_write_handler() is called, the output queue can be already empty with some streams added to h2c->posted. But after 82efcedb310b, these streams weren't processed if all frames have already been sent and the output queue was empty. This might lead to a situation when a number of streams were get stuck in h2c->posted queue for a long time. Eventually these streams might get closed by the send timeout. In the worst case this might also lead to a segmentation fault, if already freed stream was left in the h2c->posted queue. This could happen if one of the streams was terminated but wasn't closed, due to the HEADERS frame or a partially sent DATA frame left in the output queue. If this happened the ngx_http_v2_filter_cleanup() handler removed the stream from the h2c->waiting or h2c->posted queue on termination stage, before the frame has been sent, and the stream was again added to the h2c->posted queue after the frame was sent. In order to fix all these problems and simplify the code, write events of fake stream connections are now added to ngx_posted_events instead of using a custom h2c->posted queue.
2016-11-28HTTP/2: fixed saving preread buffer to temp file (ticket #1143).Valentin Bartenev1-0/+3
Previously, a request body bigger than "client_body_buffer_size" wasn't written into a temporary file if it has been pre-read entirely. The preread buffer is freed after processing, thus subsequent use of it might result in sending corrupted body or cause a segfault.
2016-11-02HTTP/2: flow control debugging.Sergey Kandaurov1-0/+4
2016-10-31HTTP/2: slightly improved debugging.Ruslan Ermilov1-3/+4
2016-10-31HTTP/2: limited maximum number of requests in connection.Valentin Bartenev3-8/+32
The new directive "http2_max_requests" is introduced. From users point of view it works quite similar to "keepalive_requests" but has significantly bigger default value that is more suitable for HTTP/2.
2016-10-20HTTP/2: graceful shutdown of active connections (closes #1106).Valentin Bartenev2-9/+39
Previously, while shutting down gracefully, the HTTP/2 connections were closed in transition to idle state after all active streams have been processed. That might never happen if the client continued opening new streams. Now, nginx sends GOAWAY to all HTTP/2 connections and ignores further attempts to open new streams. A worker process will quit as soon as processing of already opened streams is finished.
2016-10-10Allowed '-' in method names.Maxim Dounin1-1/+1
It is used at least by SOAP (M-POST method, defined by RFC 2774) and by WebDAV versioning (VERSION-CONTROL and BASELINE-CONTROL methods, defined by RFC 3253).
2016-07-19HTTP/2: flushing of the SSL buffer in transition to the idle state.Valentin Bartenev1-2/+18
It fixes potential connection leak if some unsent data was left in the SSL buffer. Particularly, that could happen when a client canceled the stream after the HEADERS frame has already been created. In this case no other frames might be produced and the HEADERS frame alone didn't flush the buffer.
2016-07-19HTTP/2: refactored ngx_http_v2_send_output_queue().Valentin Bartenev1-10/+10
Now it returns NGX_AGAIN if there's still data to be sent.
2016-07-19HTTP/2: fixed send timer handling.Valentin Bartenev1-1/+1
Checking for return value of c->send_chain() isn't sufficient since there are data can be left in the SSL buffer. Now the wew->ready flag is used instead. In particular, this fixed a connection leak in cases when all streams were closed, but there's still some data to be sent in the SSL buffer and the client forgot about the connection.
2016-07-19HTTP/2: avoid sending output queue if there's nothing to send.Valentin Bartenev1-0/+10
Particularly this fixes alerts on OS X and NetBSD systems when HTTP/2 is configured over plain TCP sockets. On these systems calling writev() with no data leads to EINVAL errors being logged as "writev() failed (22: Invalid argument) while processing HTTP/2 connection".
2016-07-19HTTP/2: always handle streams in error state.Valentin Bartenev1-6/+8
Previously, a stream could be closed by timeout if it was canceled while its send window was exhausted.
2016-07-19HTTP/2: prevented output of the HEADERS frame for canceled streams.Valentin Bartenev1-2/+6
It's useless to generate HEADERS if the stream has been canceled already.
2016-07-19HTTP/2: always send GOAWAY while worker is shutting down.Valentin Bartenev1-1/+1
Previously, if the worker process exited, GOAWAY was sent to connections in idle state, but connections with active streams were closed without GOAWAY.
2016-07-07HTTP/2: avoid left-shifting signed integer into the sign bit.Sergey Kandaurov1-1/+1
On non-aligned platforms, properly cast argument before left-shifting it in ngx_http_v2_parse_uint32 that is used with u_char. Otherwise it propagates to int to hold the value and can step over the sign bit. Usually, on known compilers, this results in negation. Furthermore, a subsequent store into a wider type, that is ngx_uint_t on 64-bit platforms, results in sign-extension. In practice, this can be observed in debug log as a very large exclusive bit value, when client sent PRIORITY frame with exclusive bit set: : *14 http2 PRIORITY frame sid:5 on 1 excl:8589934591 weight:17 Found with UndefinedBehaviorSanitizer.
2016-06-22HTTP/2: style.Piotr Sikora1-6/+4
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2016-06-20Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.Roman Arutyunyan1-22/+1
2016-06-16HTTP/2: fixed the "http request count is zero" alert.Valentin Bartenev1-0/+1
When the stream is terminated the HEADERS frame can still wait in the output queue. This frame can't be removed and must be sent to the client anyway, since HTTP/2 uses stateful compression for headers. So in order to postpone closing and freeing memory of such stream the special close stream handler is set to the write event. After the HEADERS frame is sent the write event is called and the stream will be finally closed. Some events like receiving a RST_STREAM can trigger the read handler of such stream in closing state and cause unexpected processing that can result in another attempt to finalize the request. To prevent it the read handler is now set to ngx_http_empty_handler. Thanks to Amazon.
2016-06-16HTTP/2: avoid adding Content-Length for requests without body.Valentin Bartenev1-2/+4
There is no reason to add the "Content-Length: 0" header to a proxied request without body if the header isn't presented in the original request. Thanks to Amazon.
2016-06-16HTTP/2: prevented double termination of a stream.Valentin Bartenev1-0/+5
According to RFC 7540, an endpoint should not send more than one RST_STREAM frame for any stream. Also, now all the data frames will be skipped while termination.
2016-06-16HTTP/2: fixed a segfault while processing unbuffered upload.Valentin Bartenev1-4/+0
The ngx_http_v2_finalize_connection() closes current stream, but that is an invalid operation while processing unbuffered upload. This results in access to already freed memory, since the upstream module sets a cleanup handler that also finalizes the request.
2016-05-24HTTP/2: unbreak build on MSVC.Valentin Bartenev1-1/+1
2016-05-24HTTP/2: implemented preread buffer for request body (closes #959).Valentin Bartenev4-43/+146
Previously, the stream's window was kept zero in order to prevent a client from sending the request body before it was requested (see 887cca40ba6a for details). Until such initial window was acknowledged all requests with data were rejected (see 0aa07850922f for details). That approach revealed a number of problems: 1. Some clients (notably MS IE/Edge, Safari, iOS applications) show an error or even crash if a stream is rejected; 2. This requires at least one RTT for every request with body before the client receives window update and able to send data. To overcome these problems the new directive "http2_body_preread_size" is introduced. It sets the initial window and configures a special per stream preread buffer that is used to save all incoming data before the body is requested and processed. If the directive's value is lower than the default initial window (65535), as previously, all streams with data will be rejected until the new window is acknowledged. Otherwise, no special processing is used and all requests with data are welcome right from the connection start. The default value is chosen to be 64k, which is bigger than the default initial window. Setting it to zero is fully complaint to the previous behavior.
2016-04-19HTTP/2: send the output queue after emitting WINDOW_UPDATE.Valentin Bartenev1-0/+10
The WINDOW_UPDATE frame could be left in the output queue for an indefinite period of time resulting in the request timeout. This might happen if reading of the body was triggered by an event unrelated to client connection, e.g. by the limit_req timer.
2016-04-19HTTP/2: skip data frames in case of internal errors.Valentin Bartenev1-0/+2
This prevents possible processing of such frames and triggering rb->post_handler if an error occurred during r->request_body initialization.
2016-04-19HTTP/2: don't send WINDOW_UPDATE for an empty request body.Valentin Bartenev1-12/+13
Particularly this prevents sending WINDOW_UPDATE with zero delta which can result in PROTOCOL_ERROR. Also removed surplus setting of no_flow_control to 0.
2016-04-18HTTP/2: write logs when refusing streams with data.Maxim Dounin1-0/+4
Refusing streams is known to be incorrectly handled at least by IE, Edge and Safari. Make sure to provide appropriate logging to simplify fixing this in the affected browsers.
2016-04-14HTTP/2: send WINDOW_UPDATE instead of RST_STREAM with NO_ERROR.Valentin Bartenev1-0/+22
After the 92464ebace8e change, it has been discovered that not all clients follow the RFC and handle RST_STREAM with NO_ERROR properly. Notably, Chrome currently interprets it as INTERNAL_ERROR and discards the response. As a workaround, instead of RST_STREAM the maximum stream window update will be sent, which will let client to send up to 2 GB of a request body data before getting stuck on flow control. All the received data will be silently discarded. See for details: http://mailman.nginx.org/pipermail/nginx-devel/2016-April/008143.html https://bugs.chromium.org/p/chromium/issues/detail?id=603182