Commit Graph

3719 Commits

Author SHA1 Message Date
Valentin Bartenev
fb6f8c4509 URI processing code moved to a separate function.
This allows to reuse it in the upcoming SPDY module.
2013-03-20 09:36:27 +00:00
Ruslan Ermilov
fd8b7d2f33 Image filter: the "image_filter_interlace" directive.
Patch by Ian Babrou, with minor changes.
2013-03-19 08:13:48 +00:00
Maxim Dounin
d7db87e6d9 The limit_req_status and limit_conn_status directives.
Patch by Nick Marden, with minor changes.
2013-03-18 14:50:29 +00:00
Ruslan Ermilov
5a7661e581 Core: guard against failed allocation during binary upgrade.
Patch by Piotr Sikora.
2013-03-18 07:13:57 +00:00
Valentin Bartenev
bac0cb3bbd Status: introduced the "ngx_stat_waiting" counter.
And corresponding variable $connections_waiting was added.

Previously, waiting connections were counted as the difference between
active connections and the sum of reading and writing connections.
That made it impossible to count more than one request in one connection
as reading or writing (as is the case for SPDY).

Also, we no longer count connections in handshake state as waiting.
2013-03-15 20:00:49 +00:00
Valentin Bartenev
23e692b58d Allow to reuse connections that wait their first request.
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-15 19:49:54 +00:00
Maxim Dounin
3f70ddcfc6 Upstream: fixed previous commit.
Store r->connection on stack to make sure it's still available if request
finalization happens to actually free request memory.
2013-03-14 16:22:43 +00:00
Maxim Dounin
c49abd2317 Upstream: call ngx_http_run_posted_requests() on resolve errors.
If proxy_pass to a host with dynamic resolution was used to handle
a subrequest, and host resolution failed, the main request wasn't run
till something else happened on the connection.  E.g. request to "/zzz"
with the following configuration hanged:

    addition_types *;
    resolver 8.8.8.8;

    location /test {
        set $ihost xxx;
        proxy_pass http://$ihost;
    }

    location /zzz {
      add_after_body /test;
      return 200 "test";
    }

Report and original version of the patch by Lanshun Zhou,
http://mailman.nginx.org/pipermail/nginx-devel/2013-March/003476.html.
2013-03-14 12:37:54 +00:00
Maxim Dounin
4641497e9c Request body: avoid linking rb->buf to r->header_in.
Code to reuse of r->request_body->buf in upstream module assumes it's
dedicated buffer, hence after 1.3.9 (r4931) it might reuse r->header_in
if client_body_in_file_only was set, resulting in original request
corruption.  It is considered to be safer to always create a dedicated
buffer for rb->bufs to avoid such problems.
2013-03-14 12:30:26 +00:00
Maxim Dounin
545cfd1fd3 Request body: next upstream fix.
After introduction of chunked request body handling in 1.3.9 (r4931),
r->request_body->bufs buffers have b->start pointing to original buffer
start (and b->pos pointing to real data of this particular buffer).

While this is ok as per se, it caused bad things (usually original request
headers included before the request body) after reinit of the request
chain in ngx_http_upstream_reinit() while sending the request to a next
upstream server (which used to do b->pos = b->start for each buffer
in the request chain).

Patch by Piotr Sikora.
2013-03-14 12:28:53 +00:00
Maxim Dounin
092355b2cc Fixed logging in ngx_http_wait_request_handler().
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-12 13:38:04 +00:00
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
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
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
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
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
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
Maxim Dounin
e97e4124e3 Request body: fixed client_body_in_file_only.
After introduction of chunked request body reading support in 1.3.9 (r4931),
the rb->bufs wasn't set if request body was fully preread while calling the
ngx_http_read_client_request_body() function.

Reported by Yichun Zhang (agentzh).
2013-02-01 14:38:18 +00:00
Maxim Dounin
2887c06fde SSL: fixed ngx_ssl_handshake() with level-triggered event methods.
Missing calls to ngx_handle_write_event() and ngx_handle_read_event()
resulted in a CPU hog during SSL handshake if an level-triggered event
method (e.g. select) was used.
2013-02-01 14:37:43 +00:00
Valentin Bartenev
733e6d2ac6 SSL: take into account data in the buffer while limiting output.
In some rare cases this can result in a more smooth sending rate.
2013-01-28 15:41:12 +00:00
Valentin Bartenev
0f0fac70a1 SSL: avoid calling SSL_write() with zero data size.
According to documentation, calling SSL_write() with num=0 bytes to be sent
results in undefined behavior.

We don't currently call ngx_ssl_send_chain() with empty chain and buffer.
This check handles the case of a chain with total data size that is
a multiple of NGX_SSL_BUFSIZE, and with the special buffer at the end.

In practice such cases resulted in premature connection close and critical
error "SSL_write() failed (SSL:)" in the error log.
2013-01-28 15:40:25 +00:00
Valentin Bartenev
f98b1d2561 SSL: calculation of buffer size moved closer to its usage.
No functional changes.
2013-01-28 15:38:36 +00:00
Valentin Bartenev
0f62e193dc SSL: preservation of flush flag for buffered data.
Previously, if SSL buffer was not sent we lost information that the data
must be flushed.
2013-01-28 15:37:11 +00:00
Valentin Bartenev
c857dade60 SSL: resetting of flush flag after the data was written.
There is no need to flush next chunk of data if it does not contain a buffer
with the flush or last_buf flags set.
2013-01-28 15:35:12 +00:00
Valentin Bartenev
693ba0179e SSL: removed conditions that always hold true. 2013-01-28 15:34:09 +00:00
Ruslan Ermilov
4b46b7fc5b Secure_link: fixed configuration inheritance.
The "secure_link_secret" directive was always inherited from the outer
configuration level even when "secure_link" and "secure_link_md5" were
specified on the inner level.
2013-01-28 14:42:07 +00:00
Ruslan Ermilov
33e934ccc8 Events: fixed null pointer dereference with resolver and poll.
A POLLERR signalled by poll() without POLLIN/POLLOUT, as seen on
Linux, would generate both read and write events, but there's no
write event handler for resolver events.  A fix is to only call
event handler of an active event.
2013-01-25 09:59:28 +00:00
Ruslan Ermilov
db5e48d9b8 GeoIP: IPv6 support.
When using IPv6 databases, IPv4 addresses are looked up as IPv4-mapped
IPv6 addresses.

Mostly based on a patch by Gregor Kališnik (ticket #250).
2013-01-24 16:15:51 +00:00
Maxim Dounin
aa0b86fb4d Proxy: fixed proxy_method to always add space.
Before the patch if proxy_method was specified at http{} level the code
to add trailing space wasn't executed, resulting in incorrect requests
to upstream.
2013-01-22 12:36:00 +00:00
Ruslan Ermilov
19e2ef77c2 Variables $pipe, $request_length, $time_iso8601, and $time_local.
Log module counterparts are preserved for efficiency.

Based on patch by Kiril Kalchev.
2013-01-21 13:15:29 +00:00
Ruslan Ermilov
e493f9ad4e Version bump. 2013-01-17 09:55:36 +00:00
Ruslan Ermilov
5d143ca864 Fixed and improved the "*_bind" directives of proxying modules.
The "proxy_bind", "fastcgi_bind", "uwsgi_bind", "scgi_bind" and
"memcached_bind" directives are now inherited; inherited value
can be reset by the "off" parameter.  Duplicate directives are
now detected.  Parameter value can now contain variables.
2013-01-16 09:42:57 +00:00
Ruslan Ermilov
a2a229193a Fixed "proxy_pass" with IP address and no port (ticket #276).
Upstreams created by "proxy_pass" with IP address and no port were
broken in 1.3.10, by not initializing port in u->sockaddr.

API change: ngx_parse_url() was modified to always initialize port
(in u->sockaddr and in u->port), even for the u->no_resolve case;
ngx_http_upstream() and ngx_http_upstream_add() were adopted.
2013-01-10 12:58:55 +00:00
Maxim Dounin
041449a3d3 SSL: speedup loading of configs with many ssl servers.
The patch saves one EC_KEY_generate_key() call per server{} block by
informing OpenSSL about SSL_OP_SINGLE_ECDH_USE we are going to use before
the SSL_CTX_set_tmp_ecdh() call.

For a configuration file with 10k simple server{} blocks with SSL enabled
this change reduces startup time from 18s to 5s on a slow test box here.
2013-01-09 14:11:48 +00:00
Valentin Bartenev
a6ea2f8f48 Events: added check for duplicate "events" directive. 2013-01-08 14:03:37 +00:00
Valentin Bartenev
ff2e304223 The data pointer in ngx_open_file_t objects must be initialized.
Uninitialized pointer may result in arbitrary segfaults if access_log is used
without buffer and without variables in file path.

Patch by Tatsuhiko Kubo (ticket #268).
2013-01-08 14:01:57 +00:00
Ruslan Ermilov
92d571dd71 Geo: improved code readability. 2012-12-27 21:35:47 +00:00
Ruslan Ermilov
f8a6de481c Upstream keepalive: detect duplicate "keepalive" directive.
A failure to detect duplicate "keepalive" directive resulted in
stack exhaustion.
2012-12-26 14:46:06 +00:00
Ruslan Ermilov
0a668faba4 Version bump. 2012-12-26 09:29:37 +00:00
Ruslan Ermilov
f2c8704fd0 Geo: made "default" affect both IPv4 and IPv6 when using prefixes.
Previously, "default" was equivalent to specifying 0.0.0.0/0, now
it's equivalent to specifying both 0.0.0.0/0 and ::/0 (if support
for IPv6 is enabled) with the same value.
2012-12-26 05:03:51 +00:00
Ruslan Ermilov
98129de874 Geo: properly initialize ngx_cidr_t when dealing with "default". 2012-12-25 10:00:39 +00:00
Ruslan Ermilov
3d87688bc6 Geo: IPv6 support.
The "ranges" mode is still limited to IPv4 only.
2012-12-25 08:21:56 +00:00
Valentin Bartenev
dd46cc659a Upstream: fixed state resetting when switching to backup servers.
Based on patch by Thomas Chen (ticket #257).
2012-12-25 08:02:21 +00:00
Valentin Bartenev
cb90df084f Fixed HEAD requests handling when proxying is used (closes #261). 2012-12-24 17:32:53 +00:00
Ruslan Ermilov
2189c87aa7 Trailing whitespace fix. 2012-12-24 16:40:55 +00:00
Valentin Bartenev
70d1a45c7c Access log: the "gzip" parameter of the "access_log" directive.
Note: this requires zlib version 1.2.0.4 or above to work.
2012-12-23 19:09:33 +00:00
Valentin Bartenev
fcdb4655aa Access log: the "flush" parameter of the "access_log" directive. 2012-12-23 15:51:47 +00:00
Valentin Bartenev
a8ffed5751 Reopening log files code moved to a separate function.
The code refactored in a way to call custom handler that can do appropriate
cleanup work (if any), like flushing buffers, finishing compress streams,
finalizing connections to log daemon, etc..
2012-12-23 15:36:52 +00:00
Valentin Bartenev
df71cd1125 Access log: fixed redundant buffer reallocation.
Previously a new buffer was allocated for every "access_log" directive with the
same file path and "buffer=" parameters, while only one buffer per file is used.
2012-12-23 15:27:55 +00:00
Ruslan Ermilov
7c4068d349 Properly initialize "struct in6_addr" with zeroes. 2012-12-22 20:03:38 +00:00
Maxim Dounin
4b6f8dcd2a Core: crypt_r() error handling fixed.
The crypt_r() function returns NULL on errors, check it explicitly instead
of assuming errno will remain 0 if there are no errors (per POSIX, the
setting of errno after a successful call to a function is unspecified
unless the description of that function specifies that errno shall not
be modified).

Additionally, dropped unneeded ngx_set_errno(0) and fixed error handling
of memory allocation after normal crypt(), which was inapropriate and
resulted in null pointer dereference on allocation failures.
2012-12-21 16:13:03 +00:00
Maxim Dounin
f25549210d Image filter: fixed image_filter rotate inheritance.
Configurations like

    location /i/ {
        image_filter resize 200 200;
        image_filter rotate 180;

        location /i/foo/ {
            image_filter resize 200 200;
        }
   }

resulted in rotation incorrectly applied in the location /i/foo, without
any way to clear it.  Fix is to handle conf->angle/conf->acv consistently
with other filter variables and do not try to inherit them if there are
transformations defined for current location.
2012-12-21 15:07:45 +00:00
Ruslan Ermilov
f1819242fc Geo: ensure that default entry is always present.
If 0.0.0.0/32 entry was present and there was no explicit "default",
we failed to add an empty string as a default value.
2012-12-21 08:46:52 +00:00
Ruslan Ermilov
a0caa70c98 There's no need to normalize address returned by ngx_ptocidr(). 2012-12-21 08:44:39 +00:00
Maxim Dounin
717acb74a7 Image filter: configuration inheritance fixes.
The image_filter_jpeg_quality, image_filter_sharpen and "image_filter rotate"
were inherited incorrectly if a directive with variables was defined, and
then redefined to a literal value, i.e. in configurations like

    image_filter_jpeg_quality $arg_q;

    location / {
        image_filter_jpeg_quality 50;
    }

Patch by Ian Babrou, with minor changes.
2012-12-20 19:04:28 +00:00
Ruslan Ermilov
f4b9d89103 Brought the link to ngx_http_perl_module documentation up to date. 2012-12-20 15:34:37 +00:00
Ruslan Ermilov
d03ea4d842 Fixed return type of internal function that allocates radix tree nodes. 2012-12-20 11:16:03 +00:00
Ruslan Ermilov
7ae79fb8e7 Let "add_header" affect 201 responses (ticket #125). 2012-12-19 10:33:56 +00:00
Ruslan Ermilov
30390ea492 Slightly optimized code that handles special headers in "add_header". 2012-12-19 10:30:45 +00:00
Maxim Dounin
4bad9d0505 Avoid sending "100 Continue" on 413 Request Entity Too Large.
Patch by Igor Sysoev.
2012-12-18 18:39:39 +00:00
Ruslan Ermilov
c865f8dfa2 Added checks that disallow adding a variable with an empty name.
Added variable name syntax checks to "geo" and "map" directives.
2012-12-17 19:03:33 +00:00
Ruslan Ermilov
b8a90c6903 Implemented IPv6 support for URLs specified using domain names.
This includes "debug_connection", upstreams, "proxy_pass", etc.
(ticket #92)

To preserve compatibility, "listen" specified with a domain name
selects the first IPv4 address, if available.  If not available,
the first IPv6 address will be used (ticket #186).
2012-12-17 12:08:53 +00:00
Ruslan Ermilov
2f8c1b73b8 Fixed URL parsing code.
The URL parsing code is not expected to initialize port from default port
when in "no_resolve" mode.  This got broken in r4671 for the case of IPv6
literals.
2012-12-17 09:44:46 +00:00
Ruslan Ermilov
bbf7043fe7 Simplified URL parsing code.
Except for the "listen" directive, "*" specified as a hostname is
no longer treated specially.
2012-12-17 09:31:53 +00:00
Ruslan Ermilov
18a7e1b359 Geo: fixed the "ranges" without ranges case.
The following configuration returned an empty value for $geo:

    geo $geo {
        ranges;
        default default;
    }
2012-12-14 19:56:03 +00:00
Ruslan Ermilov
cd04ca3546 Geo: improved ngx_http_geo_block() code readability. 2012-12-14 19:35:37 +00:00
Valentin Bartenev
fac3b341da Fixed handling of ngx_write_fd() and ngx_read_fd() errors.
The ngx_write_fd() and ngx_read_fd() functions return -1 in case of error,
so the incorrect comparison with NGX_FILE_ERROR (which is 0 on windows
platforms) might result in inaccurate error message in the error log.

Also the ngx_errno global variable is being set only if the returned value
is -1.
2012-12-14 15:24:24 +00:00
Valentin Bartenev
e86279e9f3 Gzip: fixed zlib memLevel adjusting.
An incorrect memLevel (lower than 1) might be passed to deflateInit2() if the
"gzip_hash" directive is set to a value less than the value of "gzip_window"
directive. This resulted in "deflateInit2() failed: -2" alert and an empty
reply.
2012-12-14 15:17:58 +00:00
Maxim Dounin
658296290c Upstream: fixed SIGSEGV with the "if" directive.
Configuration like

    location / {
        set $true 1;

        if ($true) {
            proxy_pass http://backend;
        }

        if ($true) {
            # nothing
        }
    }

resulted in segmentation fault due to NULL pointer dereference as the
upstream configuration wasn't initialized in an implicit location created
by the last if(), but the r->content_handler was set due to first if().

Instead of committing a suicide by dereferencing a NULL pointer, return
500 (Internal Server Error) in such cases, i.e. if uscf is NULL.  Better
fix would be to avoid such cases by fixing the "if" directive handling,
but it's out of scope of this patch.

Prodded by Piotr Sikora.
2012-12-13 16:05:59 +00:00
Ruslan Ermilov
ba290091cf Fixed variable syntax checking in "set", "geo", "limit_conn_zone",
and "perl_set" directives.
2012-12-13 15:05:19 +00:00
Maxim Dounin
b3430993f1 Proxy: better error message about unexpected data.
Requested by Igor Sysoev.
2012-12-13 13:45:39 +00:00
Valentin Bartenev
1a6ed2e3b1 Limit rate: fixed integer overflow in limit calculation (ticket #256).
Patch by Alexey Antropov.
2012-12-12 14:48:48 +00:00
Ruslan Ermilov
1596399e82 The "auth_basic" directive gained support of variables. 2012-12-10 13:11:11 +00:00
Ruslan Ermilov
73fb7e878f Allow the complex value to be defined as an empty string.
This makes conversion from strings to complex values possible
without the loss of functionality.
2012-12-06 23:03:53 +00:00
Ruslan Ermilov
8e8201486c Xslt: prevented infinite loop.
If XSLT transformation failed and error 500 was handled in the same
location, an infinite loop occured that exhausted the stack.
2012-12-06 21:22:58 +00:00
Ruslan Ermilov
760c55a702 Fixed build with embedded perl in certain setups (ticket #48). 2012-12-03 16:00:26 +00:00
Ruslan Ermilov
f707bea0ee Fixed the NGX_SOCKADDR_STRLEN macro definition.
The ngx_sock_ntop() function, when told to print both address and port,
prints IPv6 address in square brackets, followed by colon and port.
2012-11-30 11:26:50 +00:00
Maxim Dounin
b63da701e5 Core: removed GLOB_NOSORT glob option.
This will result in alphabetical sorting of included files if
the "include" directive with wildcards is used.

Note that the behaviour is now different from that on Windows, where
alphabetical sorting is not guaranteed for FindFirsFile()/FindNextFile()
(used to be alphabetical on NTFS, but not on FAT).

Approved by Igor Sysoev, prodded by many.
2012-11-29 23:15:41 +00:00
Maxim Dounin
ea1ff4199d Version bump. 2012-11-29 23:13:18 +00:00
Maxim Dounin
0c563970be Gunzip: added missing ngx_http_clear_etag(). 2012-11-26 21:30:45 +00:00
Maxim Dounin
1469b51451 Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Catched by dav_chunked.t on Solaris.  In released versions this might
potentially result in corruption of complex protocol responses if they
were written to disk and there were more distinct buffers than IOV_MAX
in a single write.
2012-11-26 21:19:57 +00:00
Maxim Dounin
e769544a7d Request body: block write events while reading body.
If write events are not blocked, an extra write event might happen for
various reasons (e.g. as a result of a http pipelining), resulting in
incorrect body being passed to a post handler.

The problem manifested itself with the dav module only, as this is
the only module which reads the body from a content phase handler (in
contrast to exclusive content handlers like proxy).  Additionally, dav
module used to dump core in such situations due to ticket #238.

See reports here:

http://mailman.nginx.org/pipermail/nginx-devel/2012-November/002981.html
http://serverfault.com/questions/449195/nginx-webdav-server-with-auth-request
2012-11-26 18:01:49 +00:00
Maxim Dounin
aa955a2097 Request body: error checking fixes, negative rb->rest handling.
Negative rb->rest can't happen with current code, but it's good to have
it handled anyway.

Found by Coverity (CID 744846, 744847, 744848).
2012-11-26 18:01:08 +00:00
Maxim Dounin
c4a4a6a5d8 Request body: improved handling of incorrect chunked request body.
While discarding chunked request body in some cases after detecting
request body corruption no error was returned, while it was possible
to correctly return 400 Bad Request.  If error is detected too late,
make sure to properly close connection.

Additionally, in ngx_http_special_response_handler() don't return body
of 500 Internal Server Error to a client if ngx_http_discard_request_body()
fails, but disable keepalive and continue.
2012-11-26 18:00:14 +00:00
Maxim Dounin
61feb90d74 Request body: fixed discard of chunked request body.
Even if there is no preread data, make sure to always call
ngx_http_discard_request_body_filter() in case of chunked request
body to initialize r->headers_in.content_length_n for later use.
2012-11-26 17:59:30 +00:00
Ruslan Ermilov
a94a101c79 Core: don't reuse shared memory zone that changed ownership (ticket #210).
nginx doesn't allow the same shared memory zone to be used for different
purposes, but failed to check this on reconfiguration.  If a shared memory
zone was used for another purpose in the new configuration, nginx attempted
to reuse it and crashed.
2012-11-23 12:43:58 +00:00
Ruslan Ermilov
9f385870f6 Fixed location of debug message in ngx_shmtx_lock(). 2012-11-21 14:23:26 +00:00
Maxim Dounin
542b60a35a Request body: unbreak build without debug. 2012-11-21 01:40:11 +00:00
Maxim Dounin
5fc85439d0 Request body: chunked transfer encoding support. 2012-11-21 01:08:11 +00:00
Maxim Dounin
d60b8d10f0 Request body: recalculate size of a request body in scgi module.
This allows to handle requests with chunked body by scgi module, and
also simplifies handling of various request body modifications.
2012-11-21 01:06:53 +00:00
Maxim Dounin
0ce5a3aa18 Request body: $content_length variable to honor real body size.
This allows to handle requests with chunked body by fastcgi and uwsgi
modules, and also simplifies handling of various request body modifications.
2012-11-21 01:05:08 +00:00
Maxim Dounin
9a483c8373 Request body: always use calculated size of a request body in proxy.
This allows to handle requests with chunked body, and also simplifies
handling of various request body modifications.
2012-11-21 01:03:48 +00:00
Maxim Dounin
6ddf23bdc4 Request body: adjust b->pos when chunked parsing done.
This is a nop for the current code, though will allow to correctly parse
pipelined requests.
2012-11-21 01:02:56 +00:00
Maxim Dounin
df74d88156 Request body: chunked parsing moved to ngx_http_parse.c from proxy.
No functional changes.
2012-11-21 00:59:16 +00:00
Maxim Dounin
c29837fc4d Request body: properly handle events while discarding body.
An attempt to call ngx_handle_read_event() before actually reading
data from a socket might result in read event being disabled, which is
wrong.  Catched by body.t test on Solaris.
2012-11-21 00:57:56 +00:00
Maxim Dounin
e1bd52041b Request body: fixed socket leak on errors.
The r->main->count reference counter was always incremented in
ngx_http_read_client_request_body(), while it is only needs to be
incremented on positive returns.
2012-11-21 00:57:16 +00:00
Maxim Dounin
5da61375cd Request body: code duplication reduced, no functional changes.
The r->request_body_in_file_only with empty body case is now handled in
ngx_http_write_request_body().
2012-11-21 00:55:50 +00:00
Maxim Dounin
743922a2ce Request body: $request_body variable generalization.
The $request_body variable was assuming there can't be more than two
buffers.  While this is currently true due to request body reading
implementation details, this is not a good thing to depend on and may
change in the future.
2012-11-21 00:55:06 +00:00
Maxim Dounin
ab5ac3b095 Request body: fixed "501 Not Implemented" error handling.
It is not about "Method" but a generic message, and is expected to be used
e.g. if specified Transfer-Encoding is not supported.  Fixed message to
match RFC 2616.

Additionally, disable keepalive on such errors as we won't be able to read
request body correctly if we don't understand Transfer-Encoding used.
2012-11-21 00:54:01 +00:00
Maxim Dounin
d228cf3638 Core: added debug logging of writev() in ngx_write_chain_to_file(). 2012-11-21 00:52:35 +00:00
Maxim Dounin
248bc41893 Dav: fixed segfault on PUT if body was already read (ticket #238).
If request body reading happens with different options it's possible
that there will be no r->request_body->temp_file available (or even
no r->request_body available if body was discarded).  Return internal
server error in this case instead of committing suicide by dereferencing
a null pointer.
2012-11-21 00:51:37 +00:00
Igor Sysoev
da130acfbe Fixed failure to start cache manager and cache loader processes
if there were more than 512 listening sockets in configuration.
2012-11-20 13:37:55 +00:00
Maxim Dounin
246cbd21ce Trailing whitespace fix. 2012-11-17 00:36:44 +00:00
Maxim Dounin
e1d5455a74 Upstream: better detection of connect() failures with kqueue.
Pending EOF might be reported on both read and write events, whichever
comes first, so check both of them.

Patch by Yichun Zhang (agentzh), slightly modified.
2012-11-16 18:29:19 +00:00
Ruslan Ermilov
4d0d2b20ac Upstream: honor the "down" flag for a single server.
If an upstream block was defined with the only server marked as
"down", e.g.

    upstream u {
        server 127.0.0.1:8080 down;
    }

an attempt was made to contact the server despite the "down" flag.
It is believed that immediate 502 response is better in such a
case, and it's also consistent with what is currently done in case
of multiple servers all marked as "down".
2012-11-16 12:18:05 +00:00
Ruslan Ermilov
b67dbca1ca Variables $request_time and $msec.
Log module counterparts are preserved for efficiency.
2012-11-16 09:37:14 +00:00
Ruslan Ermilov
9997aaef70 Fixed setting of CPU affinity on respawn of dead worker processes.
Worker processes are now made aware of their sequential number needed
to select CPU affinity mask.  This replaces a workaround from r4865.
2012-11-16 09:25:52 +00:00
Ruslan Ermilov
5a1d76c9f2 Version bump. 2012-11-16 07:49:41 +00:00
Maxim Dounin
8e67fb4226 Event pipe: fixed handling of buf_to_file data.
Input filter might free a buffer if there is no data in it, and in case
of first buffer (used for cache header and request header, aka p->buf_to_file)
this resulted in cache corruption.  Buffer memory was reused to read upstream
response before headers were written to disk.

Fix is to avoid moving pointers in ngx_event_pipe_add_free_buf() to a buffer
start if we were asked to free a buffer used by p->buf_to_file.

This fixes occasional cache file corruption, usually resulted
in "cache file ... has md5 collision" alerts.

Reported by Anatoli Marinov.
2012-10-30 11:14:24 +00:00
Maxim Dounin
1e12e7fa1d Variables $connection and $connection_requests.
Log module counterparts are removed as they aren't used often and
there is no need to preserve them for efficiency.
2012-10-29 17:17:59 +00:00
Maxim Dounin
7b3731862b Resolver: added missing memory allocation error handling. 2012-10-24 14:07:08 +00:00
Valentin Bartenev
09dca40b33 ngx_http_keepalive_handler() is now trying to not keep c->buffer's memory for
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-23 14:36:18 +00:00
Andrey Belov
f7b32c479d Core: the "auto" parameter of the "worker_processes" directive.
The parameter will set the number of worker processes to the
autodetected number of available CPU cores.
2012-10-23 09:08:41 +00:00
Maxim Dounin
106dbc8d76 Removed conditional compilation from waitpid() error test.
There are reports that call to a signal handler for an exited process
despite waitpid() already called for the process may happen on Linux
as well.
2012-10-18 14:48:33 +00:00
Maxim Dounin
27b7eb17d0 Gunzip: fixed r->gzip_ok check. 2012-10-18 14:27:40 +00:00
Maxim Dounin
0d7a7e91cf OCSP stapling: properly check if there is ssl.ctx.
This fixes segfault if stapling was enabled in a server without a certificate
configured (and hence no ssl.ctx).
2012-10-05 11:09:14 +00:00
Maxim Dounin
82989420ad Variable $bytes_sent.
It replicates variable $bytes_sent as previously available in log module
only.

Patch by Benjamin Grössing (with minor changes).
2012-10-03 15:25:36 +00:00
Maxim Dounin
a707811a31 Log: $apache_bytes_sent removed.
It was renamed to $body_bytes_sent in nginx 0.3.10 and the old name is
deprecated since then.
2012-10-03 15:25:06 +00:00
Maxim Dounin
c846871ce1 SSL: the "ssl_verify_client" directive parameter "optional_no_ca".
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-10-03 15:24:08 +00:00
Maxim Dounin
f8cc8969d5 Version bump. 2012-10-03 15:22:18 +00:00
Maxim Dounin
7eea509776 OCSP stapling: build fixes.
With the "ssl_stapling_verify" commit build with old OpenSSL libraries
was broken due to incorrect prototype of the ngx_ssl_stapling() function.
One incorrect use of ngx_log_debug() instead of ngx_log_debug2() slipped in
and broke win32 build.
2012-10-01 13:54:13 +00:00
Maxim Dounin
bec2cc5286 OCSP stapling: ssl_stapling_verify directive.
OCSP response verification is now switched off by default to simplify
configuration, and the ssl_stapling_verify allows to switch it on.

Note that for stapling OCSP response verification isn't something required
as it will be done by a client anyway.  But doing verification on a server
allows to mitigate some attack vectors, most notably stop an attacker from
presenting some specially crafted data to all site clients.
2012-10-01 12:53:11 +00:00
Maxim Dounin
3ebbb7d521 OCSP stapling: OCSP_basic_verify() OCSP_TRUSTOTHER flag now used.
This is expected to simplify configuration in a common case when OCSP
response is signed by a certificate already present in ssl_certificate
chain.  This case won't need any extra trusted certificates.
2012-10-01 12:51:27 +00:00
Maxim Dounin
1a07a7f2de OCSP stapling: log error data in ngx_ssl_error().
It's hard to debug OCSP_basic_verify() failures without the actual error
string it records in the error data field.
2012-10-01 12:50:36 +00:00
Maxim Dounin
872563a64d OCSP stapling: check Content-Type.
This will result in better error message in case of incorrect response
from OCSP responder:

... OCSP responder sent invalid "Content-Type" header: "text/plain"
    while requesting certificate status, responder: ...

vs.

... d2i_OCSP_RESPONSE() failed (SSL:
    error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
    error:0D068066:asn1 encoding routines:ASN1_CHECK_TLEN:bad object header
    error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error)
    while requesting certificate status, responder: ...
2012-10-01 12:48:54 +00:00
Maxim Dounin
74ad4494a6 OCSP stapling: loading OCSP responses.
This includes the ssl_stapling_responder directive (defaults to OCSP
responder set in certificate's AIA extension).

OCSP response for a given certificate is requested once we get at least
one connection with certificate_status extension in ClientHello, and
certificate status won't be sent in the connection in question.  This due
to limitations in the OpenSSL API (certificate status callback is blocking).

Note: SSL_CTX_use_certificate_chain_file() was reimplemented as it doesn't
allow to access the certificate loaded via SSL_CTX.
2012-10-01 12:47:55 +00:00
Maxim Dounin
f7ec295fb4 OCSP stapling: the ngx_event_openssl_stapling.c file.
Missed in previous commit.
2012-10-01 12:42:43 +00:00
Maxim Dounin
85c920a0cd OCSP stapling: ssl_stapling_file support.
Very basic version without any OCSP responder query code, assuming valid
DER-encoded OCSP response is present in a ssl_stapling_file configured.

Such file might be produced with openssl like this:

openssl ocsp -issuer root.crt -cert domain.crt -respout domain.staple \
             -url http://ocsp.example.com
2012-10-01 12:41:08 +00:00
Maxim Dounin
3648ba7db8 OCSP stapling: ssl_trusted_certificate directive.
The directive allows to specify additional trusted Certificate Authority
certificates to be used during certificate verification.  In contrast to
ssl_client_certificate DNs of these cerificates aren't sent to a client
during handshake.

Trusted certificates are loaded regardless of the fact whether client
certificates verification is enabled as the same certificates will be
used for OCSP stapling, during construction of an OCSP request and for
verification of an OCSP response.

The same applies to a CRL (which is now always loaded).
2012-10-01 12:39:36 +00:00
Maxim Dounin
6a0f47e079 Resolver: cached addresses are returned with random rotation now.
This ensures balancing when working with dynamically resolved upstream
servers with multiple addresses.

Based on patch by Anton Jouline.
2012-09-28 18:28:38 +00:00
Andrey Belov
8be233c8f2 Correct plural form for "path" in the whole source base. 2012-09-28 13:49:26 +00:00
Andrey Belov
b33a316883 Made sure to initialize the entire ngx_file_t structure.
Found by Coverity.
2012-09-28 13:15:11 +00:00
Maxim Dounin
52b59ebc74 SSL: added version checks for ssl compression workaround.
The SSL_COMP_get_compression_methods() is only available as an API
function in OpenSSL 0.9.8+, require it explicitly to unbreak build
with OpenSSL 0.9.7.
2012-09-27 18:01:06 +00:00
Maxim Dounin
f4f72f9fb5 SSL: fixed compression workaround to remove all methods.
Previous code used sk_SSL_COMP_delete(ssl_comp_methods, i) while iterating
stack from 0 to n, resulting in removal of only even compression methods.

In real life this change is a nop, as there is only one compression method
which is enabled by default in OpenSSL.
2012-09-27 17:59:59 +00:00
Maxim Dounin
927643e3e9 Added clearing of cpu_affinity after process spawn.
This fixes unwanted/incorrect cpu_affinity use on dead worker processes
respawn.  While this is not ideal, it's expected to be better when previous
situation where multiple processes were spawn with identical CPU affinity
set.

Reported by Charles Chen.
2012-09-26 16:25:12 +00:00
Maxim Dounin
f4473147e5 Version bump. 2012-09-26 15:52:06 +00:00
Maxim Dounin
4b948b49aa Gunzip: removed nginx.h leftover include. 2012-09-11 01:13:23 +00:00
Maxim Dounin
90bd33e8eb Gunzip filter import. 2012-09-10 16:52:47 +00:00
Maxim Dounin
86aee85d2e Gzip static: "always" parameter in "gzip_static" directive.
With "always" gzip static returns gzipped content in all cases, without
checking if client supports it.  It is useful if there are no uncompressed
files on disk anyway.
2012-09-10 16:48:25 +00:00
Maxim Dounin
23a959615e Memcached: memcached_gzip_flag directive.
This directive allows to test desired flag as returned by memcached and
sets Content-Encoding to gzip if one found.

This is reimplementation of patch by Tomash Brechko as available on
http://openhack.ru/.  It should be a bit more correct though (at least
I think so).  In particular, it doesn't try to detect if we are able to
gunzip data, but instead just sets correct Content-Encoding.
2012-09-10 16:43:49 +00:00
Maxim Dounin
5867c81fe6 Write filter: replaced unneeded loop with one to free chains.
Noted by Gabor Lekeny.
2012-09-05 15:06:47 +00:00
Valentin Bartenev
605a0ab2e1 Limit req: fix of rbtree node insertion on hash collisions.
The rbtree used in ngx_http_limit_req_module has two level of keys, the top is
hash, and the next is the value string itself. However, when inserting a new
node, only hash has been set, while the value string has been left empty.

The bug was introduced in r4419 (1.1.14).

Found by Charles Chen.
2012-09-03 12:55:50 +00:00
Ruslan Ermilov
9d6d33a561 Fixed overflow if ngx_slab_alloc() is called with very big "size" argument. 2012-08-30 15:09:21 +00:00
Ruslan Ermilov
d469482cda Fixed strict aliasing bugs when dealing with IPv4-mapped IPv6 addresses
(closes #201).
2012-08-30 14:58:11 +00:00
Ruslan Ermilov
da4ffd8955 Fixed the "include" directive.
The "include" directive should be able to include multiple files if
given a filename mask.  Fixed this to work for "include" directives
inside the "map" or "types" blocks.  The "include" directive inside
the "geo" block is still not fixed.
2012-08-28 13:31:01 +00:00
Ruslan Ermilov
43f6163063 Version bump. 2012-08-27 14:21:41 +00:00
Maxim Dounin
c22b87b2e4 Radix tree preallocation fix.
The preallocation size was calculated incorrectly and was always 8 due to
sizeof(ngx_radix_tree_t) accidentally used instead of sizeof(ngx_radix_node_t).
2012-08-18 23:17:58 +00:00
Maxim Dounin
83e35f6f22 Whitespace fix. 2012-08-18 23:04:39 +00:00
Andrey Belov
b69f284383 Mark logically dead code with corresponding comment.
Found by Coverity.
2012-08-17 15:35:50 +00:00
Maxim Dounin
572bca7b83 Mp4: removed restriction to avc1/mp4a formats (ticket #194). 2012-08-17 11:02:35 +00:00
Ruslan Ermilov
53b8514f2d Mail: fixed handling of AF_UNIX addresses in "listen".
This makes AF_UNIX addresses in mail officially supported.
2012-08-17 05:21:28 +00:00
Ruslan Ermilov
ff3236e7a7 Removed a stale "AF_INET only" comment.
IPv6 client connections in mail modules have been supported since r2856.
2012-08-17 05:14:19 +00:00
Ruslan Ermilov
f12c7563e2 Mail: fixed sorting of listen addresses (ticket #187).
For http module this problem was already fixed in r4756.
2012-08-17 05:08:42 +00:00
Maxim Dounin
5425263436 Geo: fixed handling of ranges without default set.
The bug had appeared in 0.8.43 (r3653).  Patch by Weibin Yao.
2012-08-16 13:01:41 +00:00
Maxim Dounin
89bd5f038a Crypt: fixed handling of corrupted SSHA entries in password file.
Found by Coverity.
2012-08-16 12:05:58 +00:00
Maxim Dounin
3587e2be23 Map: fixed optimization of variables as values.
Previous code incorrectly used ctx->var_values as an array of pointers to
ngx_http_variable_value_t, but the array contains structures, not pointers.
Additionally, ctx->var_values inspection failed to properly set var on
match.
2012-08-16 10:58:18 +00:00
Ruslan Ermilov
9aac01a76e mail_core: don't let the well-known port in the "listen" directive to
override the already set "protocol".
2012-08-15 11:30:24 +00:00
Ruslan Ermilov
89ad2e91e5 Corrected the directive name in the ngx_mail_auth_http_module error message. 2012-08-15 11:17:55 +00:00
Valentin Bartenev
86dd5bde45 Added three missing checks for NULL after ngx_array_push() calls.
Found by Coverity.
2012-08-08 12:03:46 +00:00
Andrey Belov
2af80d5fab Explicitly ignore returned value from close() in ngx_event_core_init_conf().
We don't have strong reason to inform about any errors
reported by close() call here, and there are no other things
to do with its return value.

Prodded by Coverity.
2012-08-07 13:57:04 +00:00
Andrey Belov
66e9525e84 Explicitly ignore returned value from unlink() in ngx_open_tempfile().
The only thing we could potentially do here in case of error
returned is to complain to error log, but we don't have log
structure available here due to interface limitations.

Prodded by Coverity.
2012-08-06 16:06:59 +00:00
Maxim Dounin
42a75bba53 Resolver: fixed possible memory leak in ngx_resolver_create().
Found by Coverity.
2012-08-06 10:48:09 +00:00
Ruslan Ermilov
8ed4929a26 Fixed the -p parameter handling.
Ensure that the path supplied always ends with a `/' except when empty.
An empty value now corresponds to the current directory instead of `/'.
2012-08-03 12:52:32 +00:00
Maxim Dounin
25197b3229 Fixed possible use of old cached times if runtime went backwards.
If ngx_time_sigsafe_update() updated only ngx_cached_err_log_time, and
then clock was adjusted backwards, the cached_time[slot].sec might
accidentally match current seconds on next ngx_time_update() call,
resulting in various cached times not being updated.

Fix is to clear the cached_time[slot].sec to explicitly mark cached times
are stale and need updating.
2012-08-03 09:10:39 +00:00
Maxim Dounin
d053bacb9c Added "const" to ngx_memcpy() with NGX_MEMCPY_LIMIT defined.
This fixes warning produced during compilation of the ngx_http_geoip_module
due to const qualifier being discarded.
2012-08-03 09:07:30 +00:00
Maxim Dounin
beaed67996 Whitespace fix. 2012-08-03 09:00:25 +00:00
Maxim Dounin
c722e8a5bf Win32: fixed build with Visual Studio 2005 Express.
It is available via winetricks which makes it still usable, and has
an old crtdefs.h which uses _CRT_SECURE_NO_DEPRECATE instead of
_CRT_SECURE_NO_WARNINGS to suppress warnings.

Reported by HAYASHI Kentaro,
http://mailman.nginx.org/pipermail/nginx-devel/2012-August/002542.html
2012-08-02 12:53:07 +00:00
Andrey Belov
1c42128e50 Reorder checks in ngx_shared_memory_add() for more consistent error messages. 2012-08-01 14:37:08 +00:00
Ruslan Ermilov
15ab0460ce Version bump. 2012-07-31 21:47:56 +00:00
Ruslan Ermilov
deaf22d220 Core: ipv6only is now on by default.
There is a general consensus that this change results in better
consistency between different operating systems and differently
tuned operating systems.

Note: this changes the width and meaning of the ipv6only field
of the ngx_listening_t structure.  3rd party modules that create
their own listening sockets might need fixing.
2012-07-30 12:27:06 +00:00
Valentin Bartenev
9c8f3d86b4 ngx_http_find_virtual_server() should return NGX_DECLINED if virtual server not
found.
2012-07-30 11:42:03 +00:00
Maxim Dounin
21be49ae59 Upstream: hide_headers/pass_headers inheritance fix.
Hide headers and pass headers arrays might not be inherited correctly
into a nested location, e.g. in configuration like

    server {
        proxy_hide_header X-Foo;
        location / {
            location /nested/ {
                proxy_pass_header X-Pad;
            }
        }
    }

the X-Foo header wasn't hidden in the location /nested/.

Reported by Konstantin Svist,
http://mailman.nginx.org/pipermail/nginx-ru/2012-July/047555.html
2012-07-30 10:35:26 +00:00
Ruslan Ermilov
1c31039d1e Improved diagnostics when a directive is specified in the wrong context. 2012-07-29 19:59:06 +00:00
Ruslan Ermilov
45d2ae646b Slight optimization in ngx_http_upstream_add(): replaced an expression
known to be constant with the constant value.
2012-07-29 19:44:09 +00:00
Ruslan Ermilov
b163010872 ngx_http_upstream_add() should return NULL if an error occurs. 2012-07-29 19:38:25 +00:00
Ruslan Ermilov
01f07bde7e Reduced the number of preprocessor directives. 2012-07-26 14:47:42 +00:00
Ruslan Ermilov
cfe194ef59 When "debug_connection" is configured with a domain name, only the first
resolved address was used.  Now all addresses will be used.
2012-07-24 17:40:06 +00:00
Ruslan Ermilov
1efcca36cc Fixed compilation with -Wmissing-prototypes. 2012-07-24 15:09:54 +00:00
Maxim Dounin
9d5f5a0c76 Win32: fixed cpu hog after process startup failure.
If ngx_spawn_process() failed while starting a process, the process
handle was closed but left non-NULL in the ngx_processes[] array.
The handle later was used in WaitForMultipleObjects() (if there
were multiple worker processes configured and at least one worker
process was started successfully), resulting in infinite loop.

Reported by Ricardo V G:
http://mailman.nginx.org/pipermail/nginx-devel/2012-July/002494.html
2012-07-23 16:37:24 +00:00
Ruslan Ermilov
54ab41f27b Fixed debugging messages to account that limit_zone was renamed to limit_conn. 2012-07-20 08:21:59 +00:00
Ruslan Ermilov
1fd21c48bb Fixed sorting of listen addresses so that wildcard address is always at
the end (closes #187).  Failure to do so could result in several listen
sockets to be created instead of only one listening on wildcard address.

Reported by Roman Odaisky.
2012-07-17 04:47:34 +00:00
Ruslan Ermilov
e30a8f90fc Version bump. 2012-07-17 04:42:38 +00:00
Maxim Dounin
e3acbc6bbb Entity tags: empty etags handling in If-Range.
Entity tag may be of length 2 as per RFC 2616, i.e. double quotes only.
Pointed out by Ruslan Ermilov.
2012-07-09 17:04:37 +00:00
Maxim Dounin
1b77858ac5 Entity tags: the "etag" directive.
It allows to disable generation of nginx's own entity tags, while
still handling ETags in cache properly.  This may be useful e.g.
if one want to serve static files from servers with different ETag
generation algorithms.
2012-07-09 14:53:42 +00:00
Maxim Dounin
eb7c38a49a Entity tags: set for static respones. 2012-07-09 00:13:06 +00:00
Maxim Dounin
8b00c87c38 Entity tags: handling in add_header.
Notably this allows to clear ETag if one want to for some reason.
2012-07-07 21:24:01 +00:00
Maxim Dounin
c96c4196f3 Entity tags: clear on entity changes. 2012-07-07 21:22:27 +00:00
Maxim Dounin
9c17e4cb66 Entity tags: support in If-Range header. 2012-07-07 21:21:15 +00:00
Maxim Dounin
13eb6898aa Entity tags: basic support in not modified filter.
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-07 21:20:27 +00:00
Maxim Dounin
a9456d55ab Not modified filter: tests separated from actions.
This makes code more extendable.  The only functional change is when
If-Modified-Since and If-Unmodified-Since are specified together, the
case which is explicitly left undefined by RFC 2616.  The new behaviour
is to respect them both, which seems better.
2012-07-07 21:18:30 +00:00
Maxim Dounin
4199620461 Added Last-Modified parsing in add_header.
This allows to use last modified time set in If-Range checks.  Code
simplified to improve readability.
2012-07-07 21:16:51 +00:00
Maxim Dounin
63d7ab16ff Fixed If-Range with unknown last modified time.
If modification time isn't known, skip range processing and return full
entity body instead of just ignoring If-Range.  Ignoring If-Range isn't
safe as client will assume entity wasn't changed since time specified.
2012-07-07 21:16:21 +00:00
Andrey Belov
3d87bcf9ae Corrected $request_length calculation for pipelined requests. 2012-07-06 04:27:06 +00:00
Ruslan Ermilov
bbfc96c703 Fixed typo in a function name. 2012-07-03 13:06:40 +00:00
Ruslan Ermilov
2219c566d7 Made sure to initialize the entire "struct flock" allocated on stack. 2012-07-03 13:05:18 +00:00
Maxim Dounin
3484e6d21c Reset r->uri_changed in a named location (ticket #184). 2012-07-03 11:30:05 +00:00
Ruslan Ermilov
f9c03b49eb map: strip final dot before looking up in a map of hostnames.
(closes #182)
2012-06-29 20:33:26 +00:00
Ruslan Ermilov
56cb80834c Version bump. 2012-06-29 11:03:01 +00:00
Maxim Dounin
a83578384c Mp4: fixed build on win32 after r4689. 2012-06-26 12:31:40 +00:00
Maxim Dounin
c6d5225e5b Style. 2012-06-25 18:09:38 +00:00
Ruslan Ermilov
8c861f06c8 Fixed a harmless error in spelling of "Connection: close" when computing
the response header length.
2012-06-25 13:08:25 +00:00
Ruslan Ermilov
42444811b9 Fixed compile-time conditionals used to detect if X-Forwarded-For support
is needed.
2012-06-21 11:02:22 +00:00
Igor Sysoev
992a4d11da Disabled gzip compression in OpenSSL prior to 1.0.0 version.
This saves about 522K per connection.
2012-06-20 12:55:28 +00:00
Ruslan Ermilov
36a931aba6 Added IPv6 support to ip_hash. 2012-06-19 12:36:54 +00:00
Maxim Dounin
29844cd55c Upstream keepalive: "single" parameter deprecated.
The original idea was to optimize edge cases in case of interchangeable
backends, i.e. don't establish a new connection if we have any one
cached.  This causes more harm than good though, as it screws up
underlying balancer's idea about backends used and may result in
various unexpected problems.
2012-06-18 14:23:42 +00:00
Maxim Dounin
91c654debc Fixed return type of ngx_strerror_init(). 2012-06-18 14:12:03 +00:00
Maxim Dounin
97f7bf25c9 Fixed "sendmsg() failed" alerts on HP-UX.
HP-UX needs _HPUX_ALT_XOPEN_SOCKET_API to be defined to be able to
use various POSIX versions of networking functions.  Notably sendmsg()
resulted in "sendmsg() failed (9: Bad file number)" alerts without it.

See xopen_networking(7) for more details.
2012-06-18 14:11:29 +00:00
Maxim Dounin
a769c530ff Fixed segfault with poll and resolver used.
Poll event method needs ngx_cycle->files to work, and use of ngx_exit_cycle
without files set caused null pointer dereference in resolver's cleanup
on udp socket close.
2012-06-18 14:10:50 +00:00
Maxim Dounin
40a366c5a8 Fixed handling of conflicting wildcard server names.
With previous code wildcard names were added to hash even if conflict
was detected.  This resulted in identical names in hash and segfault
later in ngx_hash_wildcard_init().
2012-06-18 14:06:00 +00:00
Maxim Dounin
859dc4ce01 Mp4: fixed streaming if moov atom is at buffer edge. 2012-06-18 14:02:20 +00:00
Maxim Dounin
e1e2e2eb3a Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Number of entries in stsc atom was wrong if we've added an entry to
split a chunk.

Additionally, there is no need to add an entry if we are going to split
last chunk in an entry, it's enough to update the entry we already have.
Previously new entry was added and old one was left as is, resulting in
incorrect entry with zero chunks which might confuse some software.
2012-06-18 14:01:18 +00:00
Andrey Belov
0cf52376fb Style fix. 2012-06-18 13:51:20 +00:00
Andrey Belov
e91b210b56 New core variable: $status.
Contains response status code as a 3-digit integer
(with leading zeroes if necessary), or one of the following values:

    000 - response status code has not yet been assigned
    009 - HTTP/0.9 request is being processed
2012-06-18 13:43:44 +00:00
Ruslan Ermilov
2c49af818b When "resolver" is configured with a domain name, only the first
resolved address was used.  Now all addresses will be used.
2012-06-18 12:46:05 +00:00
Ruslan Ermilov
da8bb22634 Fixed crash in ngx_resolver_cleanup_tree().
If sending a DNS request fails with an error (e.g., when mistakenly trying
to send it to a local IP broadcast), such a request is not deleted if there
are clients waiting on it.  However, it was still erroneously removed from
the queue.  Later ngx_resolver_cleanup_tree() attempted to remove it from
the queue again that resulted in a NULL pointer dereference.
2012-06-18 12:30:45 +00:00
Ruslan Ermilov
b9feaa8dd9 Version bump. 2012-06-18 11:07:44 +00:00