diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_charset_filter_module.c | 11 | ||||
-rw-r--r-- | src/http/modules/ngx_http_fastcgi_module.c | 6 | ||||
-rw-r--r-- | src/http/modules/ngx_http_memcached_module.c | 6 | ||||
-rw-r--r-- | src/http/modules/ngx_http_proxy_module.c | 6 | ||||
-rw-r--r-- | src/http/ngx_http.h | 5 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 4 | ||||
-rw-r--r-- | src/http/ngx_http_postpone_filter_module.c | 4 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 47 | ||||
-rw-r--r-- | src/http/ngx_http_request_body.c | 6 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.c | 74 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.h | 19 |
11 files changed, 109 insertions, 79 deletions
diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c index 0bc31bca5..e3fdb6542 100644 --- a/src/http/modules/ngx_http_charset_filter_module.c +++ b/src/http/modules/ngx_http_charset_filter_module.c @@ -432,6 +432,17 @@ ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in) b = cl->buf; if (ngx_buf_size(b) == 0) { + + *ll = ngx_alloc_chain_link(r->pool); + if (*ll == NULL) { + return NGX_ERROR; + } + + (*ll)->buf = b; + (*ll)->next = NULL; + + ll = &(*ll)->next; + continue; } diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c index 172a1a74d..28f860e13 100644 --- a/src/http/modules/ngx_http_fastcgi_module.c +++ b/src/http/modules/ngx_http_fastcgi_module.c @@ -168,6 +168,7 @@ static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, + { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, { ngx_null_string, 0 } }; @@ -1694,6 +1695,11 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |NGX_HTTP_UPSTREAM_FT_ERROR |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); + if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { + conf->upstream.next_upstream = NGX_CONF_BITMASK_SET + |NGX_HTTP_UPSTREAM_FT_OFF; + } + ngx_conf_merge_uint_value(conf->upstream.max_fails, prev->upstream.max_fails, 1); diff --git a/src/http/modules/ngx_http_memcached_module.c b/src/http/modules/ngx_http_memcached_module.c index 000622d94..437369265 100644 --- a/src/http/modules/ngx_http_memcached_module.c +++ b/src/http/modules/ngx_http_memcached_module.c @@ -45,6 +45,7 @@ static ngx_conf_bitmask_t ngx_http_memcached_next_upstream_masks[] = { { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, { ngx_string("invalid_response"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, { ngx_string("not_found"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, + { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, { ngx_null_string, 0 } }; @@ -560,6 +561,11 @@ ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |NGX_HTTP_UPSTREAM_FT_ERROR |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); + if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { + conf->upstream.next_upstream = NGX_CONF_BITMASK_SET + |NGX_HTTP_UPSTREAM_FT_OFF; + } + ngx_conf_merge_uint_value(conf->upstream.max_fails, prev->upstream.max_fails, 1); diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index ff5b129a8..5999f2ed2 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -127,6 +127,7 @@ static ngx_conf_bitmask_t ngx_http_proxy_next_upstream_masks[] = { { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, + { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, { ngx_null_string, 0 } }; @@ -1648,6 +1649,11 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |NGX_HTTP_UPSTREAM_FT_ERROR |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); + if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { + conf->upstream.next_upstream = NGX_CONF_BITMASK_SET + |NGX_HTTP_UPSTREAM_FT_OFF; + } + ngx_conf_merge_uint_value(conf->upstream.max_fails, prev->upstream.max_fails, 1); diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index df758707f..867f8f7d8 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -19,8 +19,8 @@ typedef struct ngx_http_log_ctx_s ngx_http_log_ctx_t; typedef ngx_int_t (*ngx_http_header_handler_pt)(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); -typedef u_char *(*ngx_http_log_handler_pt)(ngx_http_request_t *r, u_char *buf, - size_t len); +typedef u_char *(*ngx_http_log_handler_pt)(ngx_http_request_t *r, + ngx_http_request_t *sr, u_char *buf, size_t len); #if (NGX_HTTP_CACHE) @@ -49,6 +49,7 @@ typedef u_char *(*ngx_http_log_handler_pt)(ngx_http_request_t *r, u_char *buf, struct ngx_http_log_ctx_s { ngx_str_t *client; ngx_http_request_t *request; + ngx_http_request_t *current_request; }; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index b417f41c6..ee0d3ca92 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1162,6 +1162,7 @@ ngx_http_subrequest(ngx_http_request_t *r, { ngx_connection_t *c; ngx_http_request_t *sr; + ngx_http_log_ctx_t *ctx; ngx_http_core_srv_conf_t *cscf; ngx_http_postponed_request_t *pr, *p; @@ -1273,6 +1274,9 @@ ngx_http_subrequest(ngx_http_request_t *r, r->postponed = pr; } + ctx = c->log->data; + ctx->current_request = sr; + sr->internal = 1; sr->fast_subrequest = 1; diff --git a/src/http/ngx_http_postpone_filter_module.c b/src/http/ngx_http_postpone_filter_module.c index b11774810..37d200c37 100644 --- a/src/http/ngx_http_postpone_filter_module.c +++ b/src/http/ngx_http_postpone_filter_module.c @@ -162,6 +162,7 @@ ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r) { ngx_int_t rc; ngx_chain_t *out; + ngx_http_log_ctx_t *ctx; ngx_http_postponed_request_t *pr; for ( ;; ) { @@ -177,6 +178,9 @@ ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r) "http postpone filter handle \"%V?%V\"", &pr->request->uri, &pr->request->args); + ctx = r->connection->log->data; + ctx->current_request = pr->request; + if (!pr->request->done) { r->connection->data = pr->request; return NGX_AGAIN; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index bf3b0edf8..0145fe7d4 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -43,8 +43,8 @@ static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error); static void ngx_http_close_connection(ngx_connection_t *c); static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); -static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, - size_t len); +static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, + ngx_http_request_t *sr, u_char *buf, size_t len); #if (NGX_HTTP_SSL) static void ngx_http_ssl_handshake(ngx_event_t *rev); @@ -162,6 +162,7 @@ ngx_http_init_connection(ngx_connection_t *c) ctx->client = &c->addr_text; ctx->request = NULL; + ctx->current_request = NULL; c->log->connection = c->number; c->log->handler = ngx_http_log_error; @@ -427,6 +428,7 @@ ngx_http_init_request(ngx_event_t *rev) ctx = c->log->data; ctx->request = r; + ctx->current_request = r; r->log_handler = ngx_http_log_error_handler; #if (NGX_STAT_STUB) @@ -541,7 +543,6 @@ ngx_http_process_request_line(ngx_event_t *rev) ngx_int_t rc, rv; ngx_connection_t *c; ngx_http_request_t *r; - ngx_http_log_ctx_t *ctx; c = rev->data; r = c->data; @@ -722,9 +723,6 @@ ngx_http_process_request_line(ngx_event_t *rev) } if (rv == NGX_DECLINED) { - ctx = c->log->data; - ctx->request = r; - r->request_line.len = r->header_in->end - r->request_start; r->request_line.data = r->request_start; @@ -1428,10 +1426,14 @@ ngx_http_request_handler(ngx_event_t *ev) { ngx_connection_t *c; ngx_http_request_t *r; + ngx_http_log_ctx_t *ctx; c = ev->data; r = c->data; + ctx = c->log->data; + ctx->current_request = r; + if (ev->write) { r->write_event_handler(r); @@ -1445,6 +1447,7 @@ void ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) { ngx_http_request_t *pr; + ngx_http_log_ctx_t *ctx; ngx_http_core_loc_conf_t *clcf; if (rc == NGX_DONE) { @@ -1523,6 +1526,9 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) r->connection->data = pr; } + ctx = r->connection->log->data; + ctx->current_request = pr; + if (pr->postponed) { ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -2364,7 +2370,7 @@ ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len) r = ctx->request; if (r) { - return r->log_handler(r, p, len); + return r->log_handler(r, ctx->current_request, p, len); } return p; @@ -2372,9 +2378,12 @@ ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len) static u_char * -ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, size_t len) +ngx_http_log_error_handler(ngx_http_request_t *r, ngx_http_request_t *sr, + u_char *buf, size_t len) { - u_char *p; + u_char *p; + ngx_http_upstream_t *u; + ngx_peer_connection_t *peer; if (r->server_name.data) { p = ngx_snprintf(buf, len, ", server: %V", &r->server_name); @@ -2406,6 +2415,26 @@ ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf, size_t len) } } + if (r != sr) { + p = ngx_snprintf(buf, len, ", subrequest: \"%V\"", &sr->uri); + len -= p - buf; + buf = p; + } + + u = sr->upstream; + + if (u) { + peer = &u->peer; + + p = ngx_snprintf(buf, len, ", upstream: \"%V%V%s%V\"", + &u->conf->schema, + &peer->peers->peer[peer->cur_peer].name, + peer->peers->peer[peer->cur_peer].uri_separator, + &u->uri); + len -= p - buf; + buf = p; + } + return ngx_http_log_error_info(r, buf, len); } diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c index c6fa3fc09..5cc4d5225 100644 --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -92,7 +92,7 @@ ngx_http_read_client_request_body(ngx_http_request_t *r, rb->bufs->buf = b; rb->bufs->next = NULL; - if (preread >= r->headers_in.content_length_n) { + if ((off_t) preread >= r->headers_in.content_length_n) { /* the whole request body was pre-read */ @@ -120,7 +120,7 @@ ngx_http_read_client_request_body(ngx_http_request_t *r, rb->rest = r->headers_in.content_length_n - preread; - if (rb->rest <= (size_t) (b->end - b->last)) { + if (rb->rest <= (off_t) (b->end - b->last)) { /* the whole request body may be placed in r->header_in */ @@ -242,7 +242,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r) size = rb->buf->end - rb->buf->last; - if (size > rb->rest) { + if ((off_t) size > rb->rest) { size = (size_t) rb->rest; } diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 782c14be9..5caad0052 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -78,9 +78,6 @@ static size_t ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r, static u_char *ngx_http_upstream_log_response_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op); -static u_char *ngx_http_upstream_log_error(ngx_http_request_t *r, u_char *buf, - size_t len); - static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); @@ -293,7 +290,6 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = { void ngx_http_upstream_init(ngx_http_request_t *r) { - ngx_time_t *tp; ngx_connection_t *c; ngx_http_cleanup_t *cln; ngx_http_upstream_t *u; @@ -337,8 +333,6 @@ ngx_http_upstream_init(ngx_http_request_t *r) } u->peer.log = r->connection->log; - u->saved_log_handler = r->log_handler; - r->log_handler = ngx_http_upstream_log_error; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); @@ -359,18 +353,6 @@ ngx_http_upstream_init(ngx_http_request_t *r) return; } - u->state = ngx_array_push(&u->states); - if (u->state == NULL) { - ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - - ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); - - tp = ngx_timeofday(); - - u->state->response_time = tp->sec * 1000 + tp->msec; - cln = ngx_http_cleanup_add(r, 0); if (cln == NULL) { ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -528,12 +510,31 @@ static void ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) { ngx_int_t rc; + ngx_time_t *tp; ngx_connection_t *c; r->connection->log->action = "connecting to upstream"; r->connection->single_connection = 0; + if (u->state && u->state->response_time) { + tp = ngx_timeofday(); + u->state->response_time = tp->sec * 1000 + tp->msec + - u->state->response_time; + } + + u->state = ngx_array_push(&u->states); + if (u->state == NULL) { + ngx_http_upstream_finalize_request(r, u, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } + + ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); + + tp = ngx_timeofday(); + u->state->response_time = tp->sec * 1000 + tp->msec; + rc = ngx_event_connect_peer(&u->peer); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -761,15 +762,6 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) #endif - /* add one more state */ - - u->state = ngx_array_push(&u->states); - if (u->state == NULL) { - return NGX_ERROR; - } - - ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); - return NGX_OK; } @@ -1988,8 +1980,6 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r, } #endif - r->log_handler = u->saved_log_handler; - if (rc == NGX_DECLINED) { return; } @@ -2457,32 +2447,6 @@ ngx_http_upstream_log_response_time(ngx_http_request_t *r, u_char *buf, } -static u_char * -ngx_http_upstream_log_error(ngx_http_request_t *r, u_char *buf, size_t len) -{ - u_char *p; - ngx_http_upstream_t *u; - ngx_peer_connection_t *peer; - - u = r->upstream; - peer = &u->peer; - - p = ngx_snprintf(buf, len, - ", server: %V, URL: \"%V\"," - " upstream: \"%V%V%s%V\"", - &r->server_name, - &r->unparsed_uri, - &u->conf->schema, - &peer->peers->peer[peer->cur_peer].name, - peer->peers->peer[peer->cur_peer].uri_separator, - &u->uri); - len -= p - buf; - buf = p; - - return ngx_http_log_error_info(r, buf, len); -} - - static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf) { diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h index 086d184b3..8c2a90193 100644 --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -16,14 +16,15 @@ #include <ngx_http.h> -#define NGX_HTTP_UPSTREAM_FT_ERROR 0x002 -#define NGX_HTTP_UPSTREAM_FT_TIMEOUT 0x004 -#define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER 0x008 -#define NGX_HTTP_UPSTREAM_FT_HTTP_500 0x010 -#define NGX_HTTP_UPSTREAM_FT_HTTP_503 0x020 -#define NGX_HTTP_UPSTREAM_FT_HTTP_404 0x040 -#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x080 -#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x100 +#define NGX_HTTP_UPSTREAM_FT_ERROR 0x00000002 +#define NGX_HTTP_UPSTREAM_FT_TIMEOUT 0x00000004 +#define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER 0x00000008 +#define NGX_HTTP_UPSTREAM_FT_HTTP_500 0x00000010 +#define NGX_HTTP_UPSTREAM_FT_HTTP_503 0x00000020 +#define NGX_HTTP_UPSTREAM_FT_HTTP_404 0x00000040 +#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00000080 +#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00000100 +#define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000 #define NGX_HTTP_UPSTREAM_INVALID_HEADER 40 @@ -193,8 +194,6 @@ struct ngx_http_upstream_s { ngx_str_t method; - ngx_http_log_handler_pt saved_log_handler; - ngx_http_upstream_state_t *state; ngx_array_t states; /* of ngx_http_upstream_state_t */ |