diff options
author | Igor Sysoev <igor@sysoev.ru> | 2005-12-05 13:18:09 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2005-12-05 13:18:09 +0000 |
commit | d3283ff9224a41a1a24c2d89f671811c0747480a (patch) | |
tree | e122c436f72f587622e8ec0e75632434045e330d /src/http | |
parent | 0624ed3d7eaa1995d9e5ec4292bd1eccda09cafc (diff) | |
download | nginx-release-0.3.13.tar.gz nginx-release-0.3.13.zip |
nginx-0.3.13-RELEASE importrelease-0.3.13
*) Feature: the IMAP/POP3 proxy supports STARTTLS and STLS.
*) Bugfix: the IMAP/POP3 proxy did not work with the select, poll, and
/dev/poll methods.
*) Bugfix: in SSI handling.
*) Bugfix: now Solaris sendfilev() is not used to transfer the client
request body to FastCGI-server via the unix domain socket.
*) Bugfix: the "auth_basic" directive did not disable the
authorization; the bug had appeared in 0.3.11.
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_auth_basic_module.c | 2 | ||||
-rw-r--r-- | src/http/modules/ngx_http_fastcgi_module.c | 3 | ||||
-rw-r--r-- | src/http/modules/ngx_http_geo_module.c | 10 | ||||
-rw-r--r-- | src/http/modules/ngx_http_gzip_filter_module.c | 2 | ||||
-rw-r--r-- | src/http/modules/ngx_http_proxy_module.c | 10 | ||||
-rw-r--r-- | src/http/modules/ngx_http_referer_module.c | 3 | ||||
-rw-r--r-- | src/http/modules/ngx_http_ssi_filter_module.c | 6 | ||||
-rw-r--r-- | src/http/modules/ngx_http_static_module.c | 10 | ||||
-rw-r--r-- | src/http/modules/ngx_http_userid_filter_module.c | 4 | ||||
-rw-r--r-- | src/http/ngx_http_copy_filter_module.c | 21 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 40 | ||||
-rw-r--r-- | src/http/ngx_http_postpone_filter_module.c | 72 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 163 | ||||
-rw-r--r-- | src/http/ngx_http_request_body.c | 2 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.c | 96 | ||||
-rw-r--r-- | src/http/ngx_http_variables.c | 7 | ||||
-rw-r--r-- | src/http/ngx_http_variables.h | 1 | ||||
-rw-r--r-- | src/http/ngx_http_write_filter_module.c | 4 |
18 files changed, 259 insertions, 197 deletions
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c index cf855575c..48192cad1 100644 --- a/src/http/modules/ngx_http_auth_basic_module.c +++ b/src/http/modules/ngx_http_auth_basic_module.c @@ -379,6 +379,8 @@ ngx_http_auth_basic(ngx_conf_t *cf, void *post, void *data) if (ngx_strcmp(realm->data, "off") == 0) { realm->len = 0; realm->data = (u_char *) ""; + + return NGX_CONF_OK; } len = sizeof("Basic realm=\"") - 1 + realm->len + 1; diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c index 125b8e023..45b6e7382 100644 --- a/src/http/modules/ngx_http_fastcgi_module.c +++ b/src/http/modules/ngx_http_fastcgi_module.c @@ -1419,7 +1419,8 @@ ngx_http_fastcgi_add_variables(ngx_conf_t *cf) { ngx_http_variable_t *var; - var = ngx_http_add_variable(cf, &ngx_http_fastcgi_script_name, 0); + var = ngx_http_add_variable(cf, &ngx_http_fastcgi_script_name, + NGX_HTTP_VAR_NOHASH); if (var == NULL) { return NGX_ERROR; } diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c index 8231de11d..bf7b9251b 100644 --- a/src/http/modules/ngx_http_geo_module.c +++ b/src/http/modules/ngx_http_geo_module.c @@ -130,18 +130,14 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) var->handler = ngx_http_geo_variable; var->data = (uintptr_t) tree; - /* - * create the temporary pool of a huge initial size - * to process quickly a large number of geo lines - */ - - pool = ngx_create_pool(512 * 1024, cf->log); + pool = ngx_create_pool(16384, cf->log); if (pool == NULL) { return NGX_CONF_ERROR; } if (ngx_array_init(&geo.values, pool, 512, - sizeof(ngx_http_variable_value_t *)) == NGX_ERROR) + sizeof(ngx_http_variable_value_t *)) + == NGX_ERROR) { ngx_destroy_pool(pool); return NGX_CONF_ERROR; diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c index 66d59358a..e8197598f 100644 --- a/src/http/modules/ngx_http_gzip_filter_module.c +++ b/src/http/modules/ngx_http_gzip_filter_module.c @@ -961,7 +961,7 @@ ngx_http_gzip_add_variables(ngx_conf_t *cf) ngx_http_variable_t *var; ngx_http_log_op_name_t *op; - var = ngx_http_add_variable(cf, &ngx_http_gzip_ratio, 0); + var = ngx_http_add_variable(cf, &ngx_http_gzip_ratio, NGX_HTTP_VAR_NOHASH); if (var == NULL) { return NGX_ERROR; } diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 8278d34e4..afadc18ce 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -359,20 +359,20 @@ static ngx_table_elt_t ngx_http_proxy_headers[] = { static ngx_http_variable_t ngx_http_proxy_vars[] = { { ngx_string("proxy_host"), ngx_http_proxy_host_variable, 0, - NGX_HTTP_VAR_CHANGABLE, 0 }, + NGX_HTTP_VAR_CHANGABLE|NGX_HTTP_VAR_NOHASH, 0 }, { ngx_string("proxy_port"), ngx_http_proxy_port_variable, 0, - NGX_HTTP_VAR_CHANGABLE, 0 }, + NGX_HTTP_VAR_CHANGABLE|NGX_HTTP_VAR_NOHASH, 0 }, { ngx_string("proxy_add_x_forwarded_for"), - ngx_http_proxy_add_x_forwarded_for_variable, 0, 0, 0 }, + ngx_http_proxy_add_x_forwarded_for_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, #if 0 - { ngx_string("proxy_add_via"), NULL, 0, 0, 0 }, + { ngx_string("proxy_add_via"), NULL, 0, NGX_HTTP_VAR_NOHASH, 0 }, #endif { ngx_string("proxy_internal_body_length"), - ngx_http_proxy_internal_body_length_variable, 0, 0, 0 }, + ngx_http_proxy_internal_body_length_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, { ngx_null_string, NULL, 0, 0, 0 } }; diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c index a3d3d4606..cd8be7879 100644 --- a/src/http/modules/ngx_http_referer_module.c +++ b/src/http/modules/ngx_http_referer_module.c @@ -217,7 +217,8 @@ ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) name.len = sizeof("invalid_referer") - 1; name.data = (u_char *) "invalid_referer"; - var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGABLE); + var = ngx_http_add_variable(cf, &name, + NGX_HTTP_VAR_CHANGABLE|NGX_HTTP_VAR_NOHASH); if (var == NULL) { return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c index 6f4ac4555..dd0e92fcd 100644 --- a/src/http/modules/ngx_http_ssi_filter_module.c +++ b/src/http/modules/ngx_http_ssi_filter_module.c @@ -648,13 +648,17 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in) rc = cmd->handler(r, ctx, params); - if (c->closed) { + if (c->destroyed) { return NGX_DONE; } if (rc == NGX_OK) { continue; } + + if (rc == NGX_ERROR) { + return NGX_ERROR; + } } diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c index 808d945ac..1504f241d 100644 --- a/src/http/modules/ngx_http_static_module.c +++ b/src/http/modules/ngx_http_static_module.c @@ -244,6 +244,12 @@ ngx_http_static_handler(ngx_http_request_t *r) return NGX_HTTP_INTERNAL_SERVER_ERROR; } + r->allow_ranges = 1; + + if (r->header_only || (r->main != r && ngx_file_size(&fi) == 0)) { + return ngx_http_send_header(r); + } + /* we need to allocate all before the header would be sent */ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); @@ -256,11 +262,9 @@ ngx_http_static_handler(ngx_http_request_t *r) return NGX_HTTP_INTERNAL_SERVER_ERROR; } - r->allow_ranges = 1; - rc = ngx_http_send_header(r); - if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { + if (rc == NGX_ERROR || rc > NGX_OK) { return rc; } diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c index c77dca2da..159bd34c5 100644 --- a/src/http/modules/ngx_http_userid_filter_module.c +++ b/src/http/modules/ngx_http_userid_filter_module.c @@ -554,7 +554,7 @@ ngx_http_userid_add_variables(ngx_conf_t *cf) ngx_http_variable_t *var; ngx_http_log_op_name_t *op; - var = ngx_http_add_variable(cf, &ngx_http_userid_got, 0); + var = ngx_http_add_variable(cf, &ngx_http_userid_got, NGX_HTTP_VAR_NOHASH); if (var == NULL) { return NGX_ERROR; } @@ -562,7 +562,7 @@ ngx_http_userid_add_variables(ngx_conf_t *cf) var->handler = ngx_http_userid_variable; var->data = offsetof(ngx_http_userid_ctx_t, uid_got); - var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0); + var = ngx_http_add_variable(cf, &ngx_http_userid_set, NGX_HTTP_VAR_NOHASH); if (var == NULL) { return NGX_ERROR; } diff --git a/src/http/ngx_http_copy_filter_module.c b/src/http/ngx_http_copy_filter_module.c index c251273d2..bba3f5de4 100644 --- a/src/http/ngx_http_copy_filter_module.c +++ b/src/http/ngx_http_copy_filter_module.c @@ -70,11 +70,15 @@ static ngx_http_output_body_filter_pt ngx_http_next_filter; static ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in) { + ngx_int_t rc; + ngx_connection_t *c; ngx_output_chain_ctx_t *ctx; ngx_http_copy_filter_conf_t *conf; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "copy filter: \"%V\"", &r->uri); + c = r->connection; + + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, + "copy filter: \"%V?%V\"", &r->uri, &r->args); ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); @@ -88,7 +92,7 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module); - ctx->sendfile = r->connection->sendfile; + ctx->sendfile = c->sendfile; ctx->need_in_memory = r->main_filter_need_in_memory || r->filter_need_in_memory; ctx->need_in_temp = r->filter_need_temporary; @@ -102,9 +106,16 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in) } - /* the request pool may be already destroyed after ngx_output_chain()*/ + rc = ngx_output_chain(ctx, in); + +#if (NGX_DEBUG) + if (!c->destroyed) { + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); + } +#endif - return ngx_output_chain(ctx, in); + return rc; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 474338933..c100bee75 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -966,14 +966,14 @@ ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_int_t rc; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http output filter \"%V\"", &r->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http output filter \"%V?%V\"", &r->uri, &r->args); rc = ngx_http_top_body_filter(r, in); if (rc == NGX_ERROR) { /* NGX_ERROR may be returned by any filter */ - r->connection->closed = 1; + r->connection->error = 1; } return rc; @@ -1080,6 +1080,7 @@ ngx_int_t ngx_http_subrequest(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args, ngx_uint_t flags) { + ngx_connection_t *c; ngx_http_request_t *sr; ngx_http_core_srv_conf_t *cscf; ngx_http_postponed_request_t *pr, *p; @@ -1090,7 +1091,9 @@ ngx_http_subrequest(ngx_http_request_t *r, } sr->signature = NGX_HTTP_MODULE; - sr->connection = r->connection; + + c = r->connection; + sr->connection = c; sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); if (sr->ctx == NULL) { @@ -1128,16 +1131,13 @@ ngx_http_subrequest(ngx_http_request_t *r, sr->request_line = r->request_line; sr->uri = *uri; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http subrequest \"%V\"", uri); - if (args) { sr->args = *args; - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http subrequest args \"%V\"", args); } + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http subrequest \"%V?%V\"", uri, &sr->args); + if (flags & NGX_HTTP_ZERO_IN_URI) { sr->zero_in_uri = 1; } @@ -1155,8 +1155,8 @@ ngx_http_subrequest(ngx_http_request_t *r, sr->read_event_handler = ngx_http_request_empty_handler; sr->write_event_handler = ngx_http_request_empty_handler; - if (r->connection->data == r) { - sr->connection->data = sr; + if (c->data == r) { + c->data = sr; } sr->in_addr = r->in_addr; @@ -1192,7 +1192,12 @@ ngx_http_subrequest(ngx_http_request_t *r, ngx_http_handler(sr); - /* the request pool may be already destroyed */ +#if (NGX_LOG_DEBUG) + if (!c->destroyed) { + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http subrequest done \"%V?%V\"", uri, &sr->args); + } +#endif return NGX_OK; } @@ -1204,22 +1209,19 @@ ngx_http_internal_redirect(ngx_http_request_t *r, { ngx_http_core_srv_conf_t *cscf; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "internal redirect: \"%V\"", uri); - r->uri = *uri; if (args) { r->args = *args; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "internal redirect args: \"%V\"", args); - } else { r->args.len = 0; r->args.data = NULL; } + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "internal redirect: \"%V?%V\"", uri, &r->args); + if (ngx_http_set_exten(r) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } diff --git a/src/http/ngx_http_postpone_filter_module.c b/src/http/ngx_http_postpone_filter_module.c index 9c56f4669..478393cb0 100644 --- a/src/http/ngx_http_postpone_filter_module.c +++ b/src/http/ngx_http_postpone_filter_module.c @@ -9,6 +9,8 @@ #include <ngx_http.h> +static ngx_int_t + ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r); static ngx_int_t ngx_http_postpone_filter_init(ngx_cycle_t *cycle); @@ -53,8 +55,8 @@ ngx_http_postpone_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_chain_t *out; ngx_http_postponed_request_t *pr, **ppr; - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http postpone filter \"%V\" %p", &r->uri, in); + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http postpone filter \"%V?%V\" %p", &r->uri, &r->args, in); if (r != r->connection->data || (r->postponed && in)) { @@ -104,14 +106,25 @@ ngx_http_postpone_filter(ngx_http_request_t *r, ngx_chain_t *in) return NGX_OK; } - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http postpone filter out \"%V\"", &r->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http postpone filter out \"%V?%V\"", &r->uri, &r->args); rc = ngx_http_next_filter(r->main, out); if (rc == NGX_ERROR) { /* NGX_ERROR may be returned by any filter */ - r->connection->closed = 1; + r->connection->error = 1; + } + + if (r->postponed == NULL) { + return rc; + } + + rc = ngx_http_postpone_filter_output_postponed_request(r); + + if (rc == NGX_ERROR) { + /* NGX_ERROR may be returned by any filter */ + r->connection->error = 1; } return rc; @@ -119,6 +132,55 @@ ngx_http_postpone_filter(ngx_http_request_t *r, ngx_chain_t *in) static ngx_int_t +ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r) +{ + ngx_int_t rc; + ngx_http_postponed_request_t *pr; + + for ( ;; ) { + pr = r->postponed; + + if (pr == NULL) { + return NGX_OK; + } + + if (pr->request) { + + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http postpone filter handle \"%V?%V\"", + &pr->request->uri, &pr->request->args); + + if (!pr->request->done) { + r->connection->data = pr->request; + return NGX_AGAIN; + } + + rc = ngx_http_postpone_filter_output_postponed_request(pr->request); + + if (rc == NGX_AGAIN || rc == NGX_ERROR) { + return rc; + } + + r->postponed = r->postponed->next; + pr = r->postponed; + } + + if (pr->out) { + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http postpone filter out postponed \"%V?%V\"", + &r->uri, &r->args); + + if (ngx_http_next_filter(r->main, pr->out) == NGX_ERROR) { + return NGX_ERROR; + } + } + + r->postponed = r->postponed->next; + } +} + + +static ngx_int_t ngx_http_postpone_filter_init(ngx_cycle_t *cycle) { ngx_http_next_filter = ngx_http_top_body_filter; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index f6950566d..569f62e1d 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -30,7 +30,6 @@ static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r); static void ngx_http_request_handler(ngx_event_t *ev); static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); static void ngx_http_writer(ngx_http_request_t *r); -static ngx_int_t ngx_http_postponed_handler(ngx_http_request_t *r); static void ngx_http_block_read(ngx_http_request_t *r); static void ngx_http_read_discarded_body_handler(ngx_http_request_t *r); @@ -404,6 +403,8 @@ void ngx_http_init_request(ngx_event_t *rev) } c->single_connection = 1; + c->destroyed = 0; + r->connection = c; r->main = r; @@ -455,7 +456,7 @@ ngx_http_ssl_handshake(ngx_event_t *rev) return; } - n = recv(c->fd, buf, 1, MSG_PEEK); + n = recv(c->fd, (char *) buf, 1, MSG_PEEK); if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { return; @@ -1448,10 +1449,11 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) return; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http finalize request: %d, \"%V\"", rc, &r->uri); + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http finalize request: %d, \"%V?%V\"", + rc, &r->uri, &r->args); - if (rc == NGX_ERROR || r->connection->closed) { + if (rc == NGX_ERROR || r->connection->error) { ngx_http_close_request(r, 0); return; } @@ -1482,8 +1484,9 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) r->done = 1; if (r != r->connection->data) { - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http finalize non-active request: \"%V\"", &r->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http finalize non-active request: \"%V?%V\"", + &r->uri, &r->args); return; } @@ -1491,8 +1494,8 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) pr = r->parent; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http parent request: \"%V\"", &pr->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http parent request: \"%V?%V\"", &pr->uri, &pr->args); if (rc != NGX_AGAIN) { pr->connection->data = pr; @@ -1500,8 +1503,9 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) if (pr->postponed) { - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http request: \"%V\" has postponed", &pr->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http request: \"%V?%V\" has postponed", + &pr->uri, &pr->args); if (rc != NGX_AGAIN && pr->postponed->request == r) { pr->postponed = pr->postponed->next; @@ -1511,13 +1515,14 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) } } - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http request: \"%V\" still has postponed", - &pr->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http request: \"%V?%V\" still has postponed", + &pr->uri, &pr->args); - if (pr->done) { - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http wake parent request: \"%V\"", &pr->uri); + if (pr->done || pr->postponed->out) { + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http wake parent request: \"%V?%V\"", + &pr->uri, &pr->args); pr->write_event_handler(pr); } @@ -1619,8 +1624,8 @@ ngx_http_writer(ngx_http_request_t *r) c = r->connection; wev = c->write; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, wev->log, 0, - "http writer handler: \"%V\"", &r->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, wev->log, 0, + "http writer handler: \"%V?%V\"", &r->uri, &r->args); if (wev->timedout) { if (!wev->delayed) { @@ -1661,21 +1666,15 @@ ngx_http_writer(ngx_http_request_t *r) } } - if (r->postponed) { - rc = ngx_http_postponed_handler(r); - - if (rc == NGX_DONE) { - /* the request pool may be already destroyed */ - return; - } - - } else { - rc = ngx_http_output_filter(r, NULL); + rc = ngx_http_output_filter(r, NULL); + if (c->destroyed) { + return; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http writer output filter: %d, \"%V\"", rc, &r->uri); + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http writer output filter: %d, \"%V?%V\"", + rc, &r->uri, &r->args); if (rc == NGX_AGAIN) { clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); @@ -1690,67 +1689,13 @@ ngx_http_writer(ngx_http_request_t *r) return; } - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, wev->log, 0, - "http writer done: \"%V\"", &r->uri); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, wev->log, 0, + "http writer done: \"%V?%V\"", &r->uri, &r->args); ngx_http_finalize_request(r, rc); } -static ngx_int_t -ngx_http_postponed_handler(ngx_http_request_t *r) -{ - ngx_int_t rc; - ngx_http_postponed_request_t *pr; - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http postpone handler \"%V\"", &r->uri); - - pr = r->postponed; - - if (pr->request == NULL) { - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http postponed data \"%V\" %p", &r->uri, pr->out); - - rc = ngx_http_output_filter(r, NULL); - - if (rc == NGX_DONE) { - /* the request pool is already destroyed */ - return NGX_DONE; - } - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http postponed output filter: %d", rc); - - if (rc == NGX_ERROR) { - ngx_http_close_request(r, 0); - return NGX_DONE; - } - - pr = r->postponed; - - if (pr == NULL) { - - if (rc == NGX_AGAIN) { - return NGX_AGAIN; - } - - return NGX_OK; - } - } - - r = pr->request; - r->connection->data = r; - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http wake child request \"%V\"", &r->uri); - - r->write_event_handler(r); - - return NGX_DONE; -} - - static void ngx_http_block_read(ngx_http_request_t *r) { @@ -1862,7 +1807,7 @@ ngx_http_read_discarded_body(ngx_http_request_t *r) if (n == NGX_ERROR) { - r->connection->closed = 1; + r->connection->error = 1; /* * if a client request body is discarded then we already set @@ -2029,20 +1974,10 @@ ngx_http_set_keepalive(ngx_http_request_t *r) rev->handler = ngx_http_keepalive_handler; - if (wev->active) { - if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) - == NGX_ERROR) - { - ngx_http_close_connection(c); - return; - } - - } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { - ngx_http_close_connection(c); - return; - } + if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) { + if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { + ngx_http_close_connection(c); + return; } } @@ -2224,20 +2159,10 @@ ngx_http_set_lingering_close(ngx_http_request_t *r) wev = c->write; wev->handler = ngx_http_empty_handler; - if (wev->active) { - if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) - == NGX_ERROR) - { - ngx_http_close_request(r, 0); - return; - } - - } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { - ngx_http_close_request(r, 0); - return; - } + if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) { + if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { + ngx_http_close_request(r, 0); + return; } } @@ -2324,7 +2249,7 @@ void ngx_http_request_empty_handler(ngx_http_request_t *r) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http requets empty handler"); + "http request empty handler"); return; } @@ -2442,6 +2367,8 @@ ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error) r->request_line.len = 0; + r->connection->destroyed = 1; + ngx_destroy_pool(r->pool); } @@ -2469,6 +2396,8 @@ ngx_http_close_connection(ngx_connection_t *c) ngx_atomic_fetch_add(ngx_stat_active, -1); #endif + c->destroyed = 1; + pool = c->pool; ngx_close_connection(c); diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c index 779edf949..48aff74ac 100644 --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -230,7 +230,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r) } if (n == 0 || n == NGX_ERROR) { - c->closed = 1; + c->error = 1; return NGX_HTTP_BAD_REQUEST; } diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 37e979a9d..cfaca6e13 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -234,7 +234,7 @@ ngx_module_t ngx_http_upstream_module = { }; -static ngx_http_log_op_name_t ngx_http_upstream_log_fmt_ops[] = { +static ngx_http_log_op_name_t ngx_http_upstream_log_fmt_ops[] = { { ngx_string("upstream_status"), 0, NULL, ngx_http_upstream_log_status_getlen, ngx_http_upstream_log_status }, @@ -248,10 +248,10 @@ static ngx_http_log_op_name_t ngx_http_upstream_log_fmt_ops[] = { static ngx_http_variable_t ngx_http_upstream_vars[] = { { ngx_string("upstream_status"), - ngx_http_upstream_status_variable, 0, 0, 0 }, + ngx_http_upstream_status_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, { ngx_string("upstream_response_time"), - ngx_http_upstream_response_time_variable, 0, 0, 0 }, + ngx_http_upstream_response_time_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, { ngx_null_string, NULL, 0, 0, 0 } }; @@ -387,7 +387,7 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, c = r->connection; u = r->upstream; - if (c->closed) { + if (c->error) { ngx_http_upstream_finalize_request(r, u, NGX_HTTP_CLIENT_CLOSED_REQUEST); return; @@ -406,7 +406,7 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, } ev->eof = 1; - c->closed = 1; + c->error = 1; if (ev->kq_errno) { ev->error = 1; @@ -473,7 +473,7 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, } ev->eof = 1; - c->closed = 1; + c->error = 1; if (!u->cachable && u->peer.connection) { ngx_log_error(NGX_LOG_INFO, ev->log, err, @@ -1125,12 +1125,14 @@ ngx_http_upstream_process_header(ngx_event_t *rev) static void ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) { + int tcp_nodelay; ssize_t size; ngx_int_t rc; ngx_uint_t i, key; ngx_list_part_t *part; ngx_table_elt_t *h; ngx_event_pipe_t *p; + ngx_connection_t *c; ngx_pool_cleanup_t *cl; ngx_pool_cleanup_file_t *clf; ngx_http_core_loc_conf_t *clcf; @@ -1209,6 +1211,8 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) } } + c = r->connection; + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); if (u->pipe == NULL) { @@ -1231,6 +1235,23 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) return; } + if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); + + tcp_nodelay = 1; + + if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, + (const void *) &tcp_nodelay, sizeof(int)) == -1) + { + ngx_connection_error(c, ngx_socket_errno, + "setsockopt(TCP_NODELAY) failed"); + ngx_http_upstream_finalize_request(r, u, 0); + return; + } + + c->tcp_nodelay = NGX_TCP_NODELAY_SET; + } + size = u->buffer.last - u->buffer.pos; if (size) { @@ -1241,7 +1262,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) return; } - ngx_http_upstream_process_non_buffered_body(r->connection->write); + ngx_http_upstream_process_non_buffered_body(c->write); } else { u->buffer.pos = u->buffer.start; @@ -1262,7 +1283,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) if (u->cache && u->cache->ctx.file.fd != NGX_INVALID_FILE) { if (ngx_close_file(u->cache->ctx.file.fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, + ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, ngx_close_file_n " \"%s\" failed", u->cache->ctx.file.name.data); } @@ -1292,9 +1313,9 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) p->bufs = u->conf->bufs; p->busy_size = u->conf->busy_buffers_size; p->upstream = u->peer.connection; - p->downstream = r->connection; + p->downstream = c; p->pool = r->pool; - p->log = r->connection->log; + p->log = c->log; p->cachable = u->cachable; @@ -1305,7 +1326,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) } p->temp_file->file.fd = NGX_INVALID_FILE; - p->temp_file->file.log = r->connection->log; + p->temp_file->file.log = c->log; p->temp_file->path = u->conf->temp_path; p->temp_file->pool = r->pool; @@ -1364,7 +1385,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) */ p->cyclic_temp_file = 1; - r->connection->sendfile = 0; + c->sendfile = 0; } else { p->cyclic_temp_file = 0; @@ -1394,8 +1415,9 @@ ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev) size_t size; ssize_t n; ngx_buf_t *b; + ngx_int_t rc; ngx_uint_t do_write; - ngx_connection_t *c; + ngx_connection_t *c, *client; ngx_http_request_t *r; ngx_http_upstream_t *u; ngx_http_core_loc_conf_t *clcf; @@ -1426,6 +1448,7 @@ ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev) r = c->data; u = r->upstream; + client = r->connection; b = &u->buffer; @@ -1438,7 +1461,13 @@ ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev) if (do_write) { if (u->out_bufs || u->busy_bufs) { - if (ngx_http_output_filter(r, u->out_bufs) == NGX_ERROR) { + rc = ngx_http_output_filter(r, u->out_bufs); + + if (client->destroyed) { + return; + } + + if (rc == NGX_ERROR) { ngx_http_upstream_finalize_request(r, u, 0); return; } @@ -1490,18 +1519,20 @@ ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev) break; } - if (ngx_handle_write_event(r->connection->write, clcf->send_lowat) - == NGX_ERROR) - { - ngx_http_upstream_finalize_request(r, u, 0); - return; + if (client->data == r) { + if (ngx_handle_write_event(client->write, clcf->send_lowat) + == NGX_ERROR) + { + ngx_http_upstream_finalize_request(r, u, 0); + return; + } } - if (r->connection->write->active) { - ngx_add_timer(r->connection->write, clcf->send_timeout); + if (client->write->active) { + ngx_add_timer(client->write, clcf->send_timeout); - } else if (r->connection->write->timer_set) { - ngx_del_timer(r->connection->write); + } else if (client->write->timer_set) { + ngx_del_timer(client->write); } if (ngx_handle_read_event(u->peer.connection->read, 0) == NGX_ERROR) { @@ -1512,8 +1543,8 @@ ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev) if (u->peer.connection->read->active) { ngx_add_timer(u->peer.connection->read, u->conf->read_timeout); - } else if (r->connection->read->timer_set) { - ngx_del_timer(r->connection->read); + } else if (u->peer.connection->read->timer_set) { + ngx_del_timer(u->peer.connection->read); } } @@ -1577,13 +1608,14 @@ static void ngx_http_upstream_process_body(ngx_event_t *ev) { ngx_event_pipe_t *p; - ngx_connection_t *c; + ngx_connection_t *c, *downstream; ngx_http_request_t *r; ngx_http_upstream_t *u; c = ev->data; r = c->data; u = r->upstream; + downstream = r->connection; if (ev->write) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, @@ -1618,6 +1650,11 @@ ngx_http_upstream_process_body(ngx_event_t *ev) } if (ngx_event_pipe(p, ev->write) == NGX_ABORT) { + + if (downstream->destroyed) { + return; + } + ngx_http_upstream_finalize_request(r, u, 0); return; } @@ -1648,6 +1685,11 @@ ngx_http_upstream_process_body(ngx_event_t *ev) } if (ngx_event_pipe(p, ev->write) == NGX_ABORT) { + + if (downstream->destroyed) { + return; + } + ngx_http_upstream_finalize_request(r, u, 0); return; } @@ -1761,7 +1803,7 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, } } - if (r->connection->closed) { + if (r->connection->error) { ngx_http_upstream_finalize_request(r, u, NGX_HTTP_CLIENT_CLOSED_REQUEST); return; diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c index 3969d7ef0..6e831b5b0 100644 --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -843,6 +843,13 @@ ngx_http_variables_init_vars(ngx_conf_t *cf) "http variables: %ui", cmcf->variables.nelts); + for (n = 0; n < cmcf->all_variables.nelts; n++) { + if (av[n].flags & NGX_HTTP_VAR_NOHASH) { + av[n].name.data = NULL; + } + } + + /* init the all http variables hash */ cmcf->variables_hash.max_size = 500; diff --git a/src/http/ngx_http_variables.h b/src/http/ngx_http_variables.h index d1b23e8a7..480b4a574 100644 --- a/src/http/ngx_http_variables.h +++ b/src/http/ngx_http_variables.h @@ -35,6 +35,7 @@ typedef ngx_int_t (*ngx_http_get_variable_pt) (ngx_http_request_t *r, #define NGX_HTTP_VAR_CHANGABLE 1 #define NGX_HTTP_VAR_NOCACHABLE 2 #define NGX_HTTP_VAR_INDEXED 4 +#define NGX_HTTP_VAR_NOHASH 8 struct ngx_http_variable_s { diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c index f3b36225b..c4d0a0e7e 100644 --- a/src/http/ngx_http_write_filter_module.c +++ b/src/http/ngx_http_write_filter_module.c @@ -55,7 +55,7 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) c = r->connection; - if (c->closed) { + if (c->error) { return NGX_ERROR; } @@ -220,7 +220,7 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) } if (chain == NGX_CHAIN_ERROR) { - c->closed = 1; + c->error = 1; return NGX_ERROR; } |