summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_request.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2015-04-23Removed the obsolete rtsig module.Ruslan Ermilov1-1/+1
2015-04-22Removed the obsolete aio module.Ruslan Ermilov1-1/+1
2015-03-23Request body: unbuffered reading.Maxim Dounin1-0/+5
The r->request_body_no_buffering flag was introduced. It instructs client request body reading code to avoid reading the whole body, and to call post_handler early instead. The caller should use the ngx_http_read_unbuffered_request_body() function to read remaining parts of the body. Upstream module is now able to use this mode, if configured with the proxy_request_buffering directive.
2015-03-02SSL: reset ready flag if recv(MSG_PEEK) found no bytes in socket.Roman Arutyunyan1-0/+1
Previously, connection hung after calling ngx_http_ssl_handshake() with rev->ready set and no bytes in socket to read. It's possible in at least the following cases: - when processing a connection with expired TCP_DEFER_ACCEPT on Linux - after parsing PROXY protocol header if it arrived in a separate TCP packet Thanks to James Hamlin.
2014-12-02Upstream: improved subrequest logging.Maxim Dounin1-6/+2
To ensure proper logging make sure to set current_request in all event handlers, including resolve, ssl handshake, cache lock wait timer and aio read handlers. A macro ngx_http_set_log_request() introduced to simplify this.
2014-10-08Fixed possible buffer overrun in "too long header line" logging.Maxim Dounin1-3/+2
Additionally, ellipsis now always added to make it clear that the header logged is incomplete. Reported by Daniil Bondarev.
2014-08-27SPDY: avoid setting timeout on stream events in ngx_http_writer().Valentin Bartenev1-0/+6
The SPDY module doesn't expect timers can be set on stream events for reasons other than delaying output. But ngx_http_writer() could add timer on write event if the delayed flag wasn't set and nginx is waiting for AIO completion. That could cause delays in sending response over SPDY when file AIO was used.
2014-07-18Reset of r->uri.len on URI parsing errors.Maxim Dounin1-0/+2
This ensures that debug logging and the $uri variable (if used in 400 Bad Request processing) will not try to access uninitialized memory. Found by Sergey Bobrov.
2014-03-17Added server-side support for PROXY protocol v1 (ticket #355).Roman Arutyunyan1-3/+61
Client address specified in the PROXY protocol header is now saved in the $proxy_protocol_addr variable and can be used in the realip module. This is currently not implemented for mail.
2014-02-03Use ngx_socket_errno where appropriate.Piotr Sikora1-1/+1
Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-01-31Fixed false compiler warning.Vladimir Homutov1-0/+4
Newer gcc versions (4.7+) report possible use of uninitialized variable if nginx is being compiled with -O3.
2014-01-30Fixed a compile warning introduced by 01e2a5bcdd8f.Ruslan Ermilov1-3/+4
On systems with OpenSSL that has NPN support but lacks ALPN support, some compilers emitted a warning about possibly uninitialized "data" variable.
2014-01-28SSL: support ALPN (IETF's successor to NPN).Piotr Sikora1-2/+14
Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-01-28Fixed TCP_DEFER_ACCEPT handling (ticket #353).Maxim Dounin1-23/+0
Backed out 05a56ebb084a, as it turns out that kernel can return connections without any delay if syncookies are used. This basically means we can't assume anything about connections returned with deferred accept set. To solve original problem the 05a56ebb084a tried to solve, i.e. to don't wait longer than needed if a connection was accepted after deferred accept timeout, this patch changes a timeout set with setsockopt(TCP_DEFER_ACCEPT) to 1 second, unconditionally. This is believed to be enough for speed improvements, and doesn't imply major changes to timeouts used. Note that before 2.6.32 connections were dropped after a timeout. Though it is believed that 1s is still appropriate for kernels before 2.6.32, as previously tcp_synack_retries controlled the actual timeout and 1s results in more than 1 minute actual timeout by default.
2013-09-16Use EPOLLRDHUP in ngx_http_test_reading() (ticket #320).Valentin Bartenev1-0/+27
This allows to detect client connection close with pending data when the ngx_http_test_reading() request event handler is set.
2013-09-04Request cleanup code unified, no functional changes.Maxim Dounin1-1/+6
Additionally, detaching a cleanup chain from a request is a bit more resilent to various bugs if any.
2013-09-02Assume the HTTP/1.0 version by default.Valentin Bartenev1-0/+1
It is believed to be better than fallback to HTTP/0.9, because most of the clients at present time support HTTP/1.0. It allows nginx to return error response code for them in cases when it fail to parse request line, and therefore fail to detect client protocol version. Even if the client does not support HTTP/1.0, this assumption should not cause any harm, since from the HTTP/0.9 point of view it still a valid response.
2013-06-14Fixed ngx_http_test_reading() to finalize request properly.Maxim Dounin1-1/+1
Previous code called ngx_http_finalize_request() with rc = 0. This is ok if a response status was already set, but resulted in "000" being logged if it wasn't. In particular this happened with limit_req if a connection was prematurely closed during limit_req delay.
2013-05-13Fixed lingering_time check.Maxim Dounin1-2/+2
There are two significant changes in this patch: 1) The <= 0 comparison is done with a signed type. This fixes the case of ngx_time() being larger than r->lingering_time. 2) Calculation of r->lingering_time - ngx_time() is now always done in the ngx_msec_t type. This ensures the calculation is correct even if time_t is unsigned and differs in size from ngx_msec_t. Thanks to Lanshun Zhou.
2013-05-11Fixed build with --with-mail_ssl_module.Maxim Dounin1-4/+4
If nginx was compiled without --with-http_ssl_module, but with some other module which uses OpenSSL (e.g. --with-mail_ssl_module), insufficient preprocessor check resulted in build failure. The problem was introduced by e0a3714a36f8 (1.3.14). Reported by Roman Arutyunyan.
2013-03-20Preliminary experimental support for SPDY draft 2.Valentin Bartenev1-12/+60
2013-03-20URI processing code moved to a separate function.Valentin Bartenev1-120/+125
This allows to reuse it in the upcoming SPDY module.
2013-03-15Allow to reuse connections that wait their first request.Valentin Bartenev1-0/+19
This should improve behavior under deficiency of connections. Since SSL handshake usually takes significant amount of time, we exclude connections from reusable queue during this period to avoid premature flush of them.
2013-03-12Fixed logging in ngx_http_wait_request_handler().Maxim Dounin1-1/+1
If c->recv() returns 0 there is no sense in using ngx_socket_errno for logging, its value meaningless. (The code in question was copied from ngx_http_keepalive_handler(), but ngx_socket_errno makes sense there as it's used as a part of ECONNRESET handling, and the c->recv() call is preceeded by the ngx_set_socket_errno(0) call.)
2013-03-07Refactored ngx_http_init_request().Valentin Bartenev1-33/+43
Now it can be used as the request object factory with minimal impact on the connection object. Therefore it was renamed to ngx_http_create_request().
2013-03-07Removed c->single_connection flag.Valentin Bartenev1-1/+0
The c->single_connection was intended to be used as lock mechanism to serialize modifications of request object from several threads working with client and upstream connections. The flag is redundant since threads in nginx have never been used that way.
2013-03-07Respect the new behavior of TCP_DEFER_ACCEPT.Valentin Bartenev1-0/+23
In Linux 2.6.32, TCP_DEFER_ACCEPT was changed to accept connections after the deferring period is finished without any data available. (Reading from the socket returns EAGAIN in this case.) Since in nginx TCP_DEFER_ACCEPT is set to "post_accept_timeout", we do not need to wait longer if deferred accept returns with no data.
2013-03-07Use "client_header_timeout" for all requests in a connection.Valentin Bartenev1-2/+8
Previously, only the first request in a connection used timeout value from the "client_header_timeout" directive while reading header. All subsequent requests used "keepalive_timeout" for that. It happened because timeout of the read event was set to the value of "keepalive_timeout" in ngx_http_set_keepalive(), but was not removed when the next request arrived.
2013-03-07Create request object only after the first byte was received.Valentin Bartenev1-25/+102
Previously, we always created an object and logged 400 (Bad Request) in access log if a client closed connection without sending any data. Such a connection was counted as "reading". Since it's common for modern browsers to behave like this, it's no longer considered an error if a client closes connection without sending any data, and such a connection will be counted as "waiting". Now, we do not log 400 (Bad Request) and keep memory footprint as small as possible.
2013-03-01Allocate request object from its own pool.Valentin Bartenev1-38/+32
Previously, it was allocated from a connection pool and was selectively freed for an idle keepalive connection. The goal is to put coupled things in one chunk of memory, and to simplify handling of request objects.
2013-02-27SNI: added restriction on requesting host other than negotiated.Valentin Bartenev1-0/+12
According to RFC 6066, client is not supposed to request a different server name at the application layer. Server implementations that rely upon these names being equal must validate that a client did not send a different name in HTTP request. Current versions of Apache HTTP server always return 400 "Bad Request" in such cases. There exist implementations however (e.g., SPDY) that rely on being able to request different host names in one connection. Given this, we only reject requests with differing host names if verification of client certificates is enabled in a corresponding server configuration. An example of configuration that might not work as expected: server { listen 433 ssl default; return 404; } server { listen 433 ssl; server_name example.org; ssl_client_certificate org.cert; ssl_verify_client on; } server { listen 433 ssl; server_name example.com; ssl_client_certificate com.cert; ssl_verify_client on; } Previously, a client was able to request example.com by presenting a certificate for example.org, and vice versa.
2013-02-27SNI: reset to default server if requested host was not found.Valentin Bartenev1-0/+11
Not only this is consistent with a case without SNI, but this also prevents abusing configurations that assume that the $host variable is limited to one of the configured names for a server. An example of potentially unsafe configuration: server { listen 443 ssl default_server; ... } server { listen 443; server_name example.com; location / { proxy_pass http://$host; } } Note: it is possible to negotiate "example.com" by SNI, and to request arbitrary host name that does not exist in the configuration above.
2013-02-27SNI: avoid surplus lookup of virtual server if SNI was used.Valentin Bartenev1-0/+34
2013-02-27Apply server configuration as soon as host is known.Valentin Bartenev1-4/+18
Previously, this was done only after the whole request header was parsed, and if an error occurred earlier then the request was processed in the default server (or server chosen by SNI), while r->headers_in.server might be set to the value from the Host: header or host from request line. r->headers_in.server is in turn used for $host variable and in HTTP redirects if "server_name_in_redirect" is disabled. Without the change, configurations that rely on this during error handling are potentially unsafe if SNI is used. This change also allows to use server specific settings of "underscores_in_headers", "ignore_invalid_headers", and "large_client_header_buffers" directives for HTTP requests and HTTPS requests without SNI.
2013-02-27SSL: do not treat SSL handshake as request.Valentin Bartenev1-88/+98
The request object will not be created until SSL handshake is complete. This simplifies adding another connection handler that does not need request object right after handshake (e.g., SPDY). There are also a few more intentional effects: - the "client_header_buffer_size" directive will be taken from the server configuration that was negotiated by SNI; - SSL handshake errors and timeouts are not logged into access log as bad requests; - ngx_ssl_create_connection() is not called until the first byte of ClientHello message was received. This also decreases memory consumption if plain HTTP request is sent to SSL socket.
2013-02-27Status: do not count connection as reading right after accept().Valentin Bartenev1-19/+0
Before we receive the first bytes, the connection is counted as waiting. This change simplifies further code changes.
2013-02-27SNI: reuse selected configuration for all requests in a connection.Valentin Bartenev1-6/+10
Previously, only the first request in a connection was assigned the configuration selected by SNI. All subsequent requests initially used the default server's configuration, ignoring SNI, which was wrong. Now all subsequent requests in a connection will initially use the configuration selected by SNI. This is done by storing a pointer to configuration in http connection object. It points to default server's configuration initially, but changed upon receipt of SNI. (The request's configuration can be further refined when parsing the request line and Host: header.) This change was not made specific to SNI as it also allows slightly faster access to configuration without the request object.
2013-02-27SNI: ignore captures in server_name regexes when matching by SNI.Valentin Bartenev1-43/+103
This change helps to decouple ngx_http_ssl_servername() from the request object. Note: now we close connection in case of error during server name lookup for request. Previously, we did so only for HTTP/0.9 requests.
2013-02-27Changed interface of ngx_http_validate_host().Valentin Bartenev1-42/+44
2013-02-27Introduced the ngx_http_set_connection_log() macro.Valentin Bartenev1-8/+3
No functional changes.
2013-02-27The default server lookup is now done only once per connection.Valentin Bartenev1-103/+104
Previously, it was done for every request in a connection.
2013-02-27Correctly handle multiple X-Forwarded-For headers (ticket #106).Ruslan Ermilov1-21/+24
2013-02-23Fixed potential segfault in ngx_http_keepalive_handler().Valentin Bartenev1-0/+1
In case of error in the read event handling we close a connection by calling ngx_http_close_connection(), that also destroys connection pool. Thereafter, an attempt to free a buffer (added in r4892) that was allocated from the pool could cause SIGSEGV and is meaningless as well (the buffer already freed with the pool).
2013-02-18Proxy: support for connection upgrade (101 Switching Protocols).Maxim Dounin1-0/+4
This allows to proxy WebSockets by using configuration like this: location /chat/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } Connection upgrade is allowed as long as it was requested by a client via the Upgrade request header.
2012-11-21Request body: chunked transfer encoding support.Maxim Dounin1-17/+20
2012-10-23ngx_http_keepalive_handler() is now trying to not keep c->buffer's memory forValentin Bartenev1-0/+14
idle connections. This behaviour is consistent with the ngx_http_set_keepalive() function and it should decrease memory usage in some cases (especially if epoll/rtsig is used).
2012-10-03SSL: the "ssl_verify_client" directive parameter "optional_no_ca".Maxim Dounin1-1/+3
This parameter allows to don't require certificate to be signed by a trusted CA, e.g. if CA certificate isn't known in advance, like in WebID protocol. Note that it doesn't add any security unless the certificate is actually checked to be trusted by some external means (e.g. by a backend). Patch by Mike Kazantsev, Eric O'Connor.
2012-07-30ngx_http_find_virtual_server() should return NGX_DECLINED if virtual server notValentin Bartenev1-1/+1
found.
2012-07-07Entity tags: basic support in not modified filter.Maxim Dounin1-0/+8
This includes handling of ETag headers (if present in a response) with basic support for If-Match, If-None-Match conditionals in not modified filter. Note that the "r->headers_out.last_modified_time == -1" check in the not modified filter is left as is intentionally. It's to prevent handling of If-* headers in case of proxy without cache (much like currently done with If-Modified-Since).
2012-07-06Corrected $request_length calculation for pipelined requests.Andrey Belov1-7/+4