Commit Graph

4403 Commits

Author SHA1 Message Date
Valentin Bartenev
f1b6e47b74 Removed unused prototype of ngx_http_find_server_conf().
This function prototype and its implementation was added in r90,
but the implementation was removed in r97.
2013-03-11 14:44:56 +00:00
Valentin Bartenev
b8cba361f7 Gzip: fixed setting of NGX_HTTP_GZIP_BUFFERED.
In r2411 setting of NGX_HTTP_GZIP_BUFFERED in c->buffered was moved from
ngx_http_gzip_filter_deflate_start() to ngx_http_gzip_filter_buffer() since
it was always called first.  But in r2543 the "postpone_gzipping" directive
was introduced, and if postponed gzipping is disabled (the default setting),
ngx_http_gzip_filter_buffer() is not called at all.

We must always set NGX_HTTP_GZIP_BUFFERED after the start of compression
since there is always a trailer that is buffered.

There are no known cases when it leads to any problem with current code.
But we already had troubles in upcoming SPDY implementation.
2013-03-11 11:19:58 +00:00
Valentin Bartenev
8fbef4841f SSL: Next Protocol Negotiation extension support.
Not only this is useful for the upcoming SPDY support, but it can
also help to improve HTTPS performance by enabling TLS False Start
in Chrome/Chromium browsers [1].  So, we always enable NPN for HTTPS
if it is supported by OpenSSL.

[1] http://www.imperialviolet.org/2012/04/11/falsestart.html
2013-03-07 18:21:28 +00:00
Valentin Bartenev
bf23093e10 Refactored ngx_http_init_request().
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-07 18:14:27 +00:00
Valentin Bartenev
a32d3f8b6b Removed c->single_connection flag.
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-07 18:07:16 +00:00
Valentin Bartenev
4815b3b2ee Respect the new behavior of TCP_DEFER_ACCEPT.
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-07 17:59:27 +00:00
Valentin Bartenev
3e5aaee828 Use "client_header_timeout" for all requests in a connection.
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-07 17:41:40 +00:00
Valentin Bartenev
a46a3ab68d Create request object only after the first byte was received.
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-07 17:21:50 +00:00
Valentin Bartenev
1e1b93b51f Version bump. 2013-03-07 17:07:04 +00:00
Maxim Dounin
86402932b7 release-1.3.14 tag 2013-03-05 14:36:20 +00:00
Maxim Dounin
7dcc731118 nginx-1.3.14-RELEASE 2013-03-05 14:35:58 +00:00
Maxim Dounin
b502fcb37a Mp4: fixed handling of too small mdat atoms (ticket #266).
Patch by Gernot Vormayr (with minor changes).
2013-03-04 15:39:03 +00:00
Valentin Bartenev
fcf003c6f4 Allocate request object from its own pool.
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-03-01 14:55:42 +00:00
Valentin Bartenev
b720f650bb SNI: added restriction on requesting host other than negotiated.
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-27 17:41:34 +00:00
Valentin Bartenev
6000f4ad6d SNI: reset to default server if requested host was not found.
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-27 17:38:54 +00:00
Valentin Bartenev
f61612532c SNI: avoid surplus lookup of virtual server if SNI was used. 2013-02-27 17:33:59 +00:00
Valentin Bartenev
8c4fea1766 Apply server configuration as soon as host is known.
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-27 17:27:15 +00:00
Valentin Bartenev
d281d0ba8b SSL: do not treat SSL handshake as request.
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-27 17:21:21 +00:00
Valentin Bartenev
167aabf2b3 Status: do not count connection as reading right after accept().
Before we receive the first bytes, the connection is counted
as waiting.

This change simplifies further code changes.
2013-02-27 17:16:51 +00:00
Valentin Bartenev
64932a9714 SNI: reuse selected configuration for all requests in a connection.
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-27 17:12:48 +00:00
Valentin Bartenev
e1d8158b5e SNI: ignore captures in server_name regexes when matching by SNI.
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-27 17:06:52 +00:00
Valentin Bartenev
8ca4dff8c8 Changed interface of ngx_http_validate_host(). 2013-02-27 17:03:14 +00:00
Valentin Bartenev
b314102ff1 Introduced the ngx_http_set_connection_log() macro.
No functional changes.
2013-02-27 16:56:47 +00:00
Valentin Bartenev
508afb8cf5 The default server lookup is now done only once per connection.
Previously, it was done for every request in a connection.
2013-02-27 16:53:01 +00:00
Ruslan Ermilov
67a68720b7 Correctly handle multiple X-Forwarded-For headers (ticket #106). 2013-02-27 13:29:50 +00:00
Ruslan Ermilov
40ea120b34 Fixed separator in $sent_http_cache_control.
In case multiple "Cache-Control" headers are sent to a client,
multiple values in $sent_http_cache_control were incorrectly
split by a semicolon.  Now they are split by a comma.
2013-02-27 13:22:20 +00:00
Valentin Bartenev
f1d5d03eee Fixed potential segfault in ngx_http_keepalive_handler().
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-23 13:23:48 +00:00
Maxim Dounin
890ee444ca SSL: retry "sess_id" and "id" allocations.
In case of fully populated SSL session cache with no memory left for
new allocations, ngx_ssl_new_session() will try to expire the oldest
non-expired session and retry, but only in case when slab allocation
fails for "cached_sess", not when slab allocation fails for either
"sess_id" or "id", which can happen for number of reasons and results
in new session not being cached.

Patch fixes this by adding retry logic to "sess_id" & "id" allocations.

Patch by Piotr Sikora.
2013-02-23 11:54:25 +00:00
Maxim Dounin
56bc5f250b Trailing whitespace fix. 2013-02-23 11:50:42 +00:00
Andrey Belov
284a7dbb30 Introduced variables in ngx_http_stub_status module.
Three new variables were added: $connections_active, $connections_reading
and $connections_writing.
2013-02-21 23:31:57 +00:00
Maxim Dounin
208fc03e7c Connection upgrade support in uwsgi and scgi modules.
Prodded by Roberto De Ioris.
2013-02-20 16:41:05 +00:00
Valentin Bartenev
59db08a6fc Removed zero termination of shm zone names.
It was added in r2717 and no longer needed since r2721,
where the termination was added to ngx_shm_alloc() and
ngx_init_zone_pool().  So then it only corrupts error
messages about ivalid zones.
2013-02-19 17:48:45 +00:00
Valentin Bartenev
a98305e363 Version bump. 2013-02-19 17:45:12 +00:00
Maxim Dounin
2154327e9c release-1.3.13 tag 2013-02-19 15:15:11 +00:00
Maxim Dounin
a7b410419f nginx-1.3.13-RELEASE 2013-02-19 15:14:48 +00:00
Maxim Dounin
82d48e1eba Proxy: fixed do_write handling in previous commit.
As rightfully complained by MSVC, do_write variable was used uninitialized.
Correct fix is to set it's initial value based on event happened.
2013-02-18 15:08:46 +00:00
Maxim Dounin
08a73b4aad Proxy: support for connection upgrade (101 Switching Protocols).
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.
2013-02-18 13:50:52 +00:00
Gleb Smirnoff
35c17ea6f5 Configure: changed default compiler from "gcc" to "cc".
This allows to automatically pick the preferred system compiler on
systems with multiple compilers.

Reviewed by:	mdounin, ru
2013-02-18 11:35:28 +00:00
Maxim Dounin
7022bc28ea Configure: rebuild perl module nginx.so if headers are changed.
Note: the "-p" argument of cp(1) dropped intentionally, to force nginx.so
rebuild.  It is considered too boring to properly list all dependencies
in Makefile.PL.
2013-02-15 16:50:22 +00:00
Maxim Dounin
d2c9f4554f Fixed false memset warning on Linux with -O3 (ticket #275).
Prodded by John Leach.
2013-02-13 14:39:46 +00:00
Maxim Dounin
2761d480a2 Updated OpenSSL used for win32 builds. 2013-02-11 23:37:20 +00:00
Maxim Dounin
a2b987e79f Added support for {SHA} passwords (ticket #50).
Note: use of {SHA} passwords is discouraged as {SHA} password scheme is
vulnerable to attacks using rainbow tables.  Use of {SSHA}, $apr1$ or
crypt() algorithms as supported by OS is recommended instead.

The {SHA} password scheme support is added to avoid the need of changing
the scheme recorded in password files from {SHA} to {SSHA} because such
a change hides security problem with {SHA} passwords.

Patch by Louis Opter, with minor changes.
2013-02-07 12:09:56 +00:00
Maxim Dounin
6cb9bbe71c Version bump. 2013-02-07 12:09:09 +00:00
Maxim Dounin
e757c8d2e3 release-1.3.12 tag 2013-02-05 14:07:01 +00:00
Maxim Dounin
a24e00fbbc nginx-1.3.12-RELEASE 2013-02-05 14:06:41 +00:00
Maxim Dounin
94bee544a0 Updated OpenSSL used for win32 builds. 2013-02-05 13:41:48 +00:00
Ruslan Ermilov
75e5d13ec6 GeoIP: removed pseudo-support of "proxy" and "netspeed" databases. 2013-02-04 16:44:22 +00:00
Maxim Dounin
aad0a1dba6 FastCGI: proper handling of split fastcgi end request.
If fastcgi end request record was split between several network packets,
with fastcgi_keep_conn it was possible that connection was saved in incorrect
state (e.g. with padding bytes not yet read).
2013-02-01 14:41:50 +00:00
Maxim Dounin
e8efec0e5e FastCGI: unconditional state transitions.
Checks for f->padding before state transitions make code hard to follow,
remove them and make sure we always do another loop iteration after
f->state is set to ngx_http_fastcgi_st_padding.
2013-02-01 14:41:07 +00:00
Maxim Dounin
1c5fce7518 FastCGI: fixed wrong connection close with fastcgi_keep_conn.
With fastcgi_keep_conn it was possible that connection was closed after
FCGI_STDERR record with zero padding and without any further data read yet.
This happended as f->state was set to ngx_http_fastcgi_st_padding and then
"break" happened, resulting in p->length being set to f->padding, i.e. 0
(which in turn resulted in connection close).

Fix is to make sure we continue the loop after f->state is set.
2013-02-01 14:40:19 +00:00