The default server lookup is now done only once per connection.

Previously, it was done for every request in a connection.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5086 73f98a42-aea0-e011-b76d-00259023448c
Introduced the ngx_http_set_connection_log() macro.

No functional changes.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5087 73f98a42-aea0-e011-b76d-00259023448c
Changed interface of ngx_http_validate_host().


git-svn-id: svn://svn.nginx.org/nginx/trunk@5088 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5089 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5090 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5091 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5092 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5093 73f98a42-aea0-e011-b76d-00259023448c
SNI: avoid surplus lookup of virtual server if SNI was used.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5094 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5095 73f98a42-aea0-e011-b76d-00259023448c
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.


git-svn-id: svn://svn.nginx.org/nginx/trunk@5096 73f98a42-aea0-e011-b76d-00259023448c