diff options
author | Igor Sysoev <igor@sysoev.ru> | 2005-02-09 17:31:07 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2005-02-09 17:31:07 +0300 |
commit | aa8286101a57f11f2c1f9b5bf2d7ec121e74beea (patch) | |
tree | d87e4d87bf388c7a3c630170d9ba43a8591007ed /src/http | |
parent | 9ef28fa32a4713d365aa8d4cfc1f8732d6de47f6 (diff) |
nginx-0.1.18-RELEASE importrelease-0.1.18
*) Workaround: the default values of the devpoll_events and the
devpoll_changes directives changed from 512 to 32 to be compatible
with Solaris 10.
*) Bugfix: the proxy_set_x_var and fastcgi_set_var directives were not
inherited.
*) Bugfix: in the redirect rewrite directive the arguments were
concatenated with URI by the "&" rather than the "?".
*) Bugfix: the lines without trailing ";" in the file being included by
the ngx_http_geo_module were silently ignored.
*) Feature: the ngx_http_stub_status_module.
*) Bugfix: the unknown log format in the access_log directive caused
the segmentation fault.
*) Feature: the new "document_root" parameter of the fastcgi_params
directive.
*) Feature: the fastcgi_redirect_errors directive.
*) Feature: the new "break" modifier of the "rewrite" directive allows
to stop the rewrite/location cycle and sets the current
configuration to the request.
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_fastcgi_handler.c | 205 | ||||
-rw-r--r-- | src/http/modules/ngx_http_geo_module.c | 2 | ||||
-rw-r--r-- | src/http/modules/ngx_http_rewrite_handler.c | 106 | ||||
-rw-r--r-- | src/http/modules/ngx_http_stub_status_module.c | 138 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 14 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 2 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 55 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 348 | ||||
-rw-r--r-- | src/http/ngx_http_log_handler.c | 5 | ||||
-rw-r--r-- | src/http/ngx_http_special_response.c | 3 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.c | 117 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.h | 8 |
12 files changed, 662 insertions, 341 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_handler.c index 828f7accc..43f99ca41 100644 --- a/src/http/modules/ngx_http_fastcgi_handler.c +++ b/src/http/modules/ngx_http_fastcgi_handler.c @@ -20,7 +20,7 @@ typedef struct { ngx_str_t root; ngx_str_t index; - ngx_array_t vars; + ngx_array_t *vars; ngx_str_t *location; } ngx_http_fastcgi_loc_conf_t; @@ -84,6 +84,7 @@ typedef struct { #define NGX_HTTP_FASTCGI_GATEWAY_INTERFACE 0x0400 #define NGX_HTTP_FASTCGI_REQUEST_URI 0x0800 #define NGX_HTTP_FASTCGI_REDIRECT_STATUS 0x1000 +#define NGX_HTTP_FASTCGI_DOCUMENT_ROOT 0x2000 #define NGX_HTTP_FASTCGI_RESPONDER 1 @@ -123,22 +124,22 @@ static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r); static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r); static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r); static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, - ngx_buf_t *buf); + ngx_buf_t *buf); static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r, - ngx_http_fastcgi_ctx_t *f); + ngx_http_fastcgi_ctx_t *f); static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r); static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, - ngx_int_t rc); + ngx_int_t rc); static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, - void *data); + void *data); static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, - void *parent, void *child); + void *parent, void *child); static ngx_str_t ngx_http_fastcgi_methods[] = { @@ -155,17 +156,17 @@ static ngx_http_header_t ngx_http_fastcgi_headers_in[] = { { ngx_string("Status"), offsetof(ngx_http_fastcgi_headers_in_t, status) }, { ngx_string("Content-Type"), - offsetof(ngx_http_fastcgi_headers_in_t, content_type) }, + offsetof(ngx_http_fastcgi_headers_in_t, content_type) }, { ngx_string("Content-Length"), - offsetof(ngx_http_fastcgi_headers_in_t, content_length) }, + offsetof(ngx_http_fastcgi_headers_in_t, content_length) }, { ngx_string("X-Powered-By"), - offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) }, + offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) }, #if (NGX_HTTP_GZIP) { ngx_string("Content-Encoding"), - offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) }, + offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) }, #endif { ngx_null_string, 0 } @@ -173,7 +174,7 @@ static ngx_http_header_t ngx_http_fastcgi_headers_in[] = { static ngx_conf_post_t ngx_http_fastcgi_lowat_post = - { ngx_http_fastcgi_lowat_check } ; + { ngx_http_fastcgi_lowat_check }; static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, @@ -198,6 +199,7 @@ static ngx_conf_bitmask_t ngx_http_fastcgi_params_masks[] = { { ngx_string("redirect_status"), NGX_HTTP_FASTCGI_REDIRECT_STATUS }, { ngx_string("request_uri"), NGX_HTTP_FASTCGI_REQUEST_URI }, + { ngx_string("document_root"), NGX_HTTP_FASTCGI_DOCUMENT_ROOT }, { ngx_null_string, 0 } }; @@ -254,6 +256,13 @@ static ngx_command_t ngx_http_fastcgi_commands[] = { offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size), NULL }, + { ngx_string("fastcgi_redirect_errors"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_fastcgi_loc_conf_t, upstream.redirect_errors), + NULL }, + { ngx_string("fastcgi_x_powered_by"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_flag_slot, @@ -352,7 +361,8 @@ ngx_module_t ngx_http_fastcgi_module = { }; -static ngx_int_t ngx_http_fastcgi_handler(ngx_http_request_t *r) +static ngx_int_t +ngx_http_fastcgi_handler(ngx_http_request_t *r) { ngx_int_t rc; ngx_http_upstream_t *u; @@ -408,7 +418,8 @@ static ngx_int_t ngx_http_fastcgi_handler(ngx_http_request_t *r) } -static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) +static ngx_int_t +ngx_http_fastcgi_create_request(ngx_http_request_t *r) { u_char ch, *pos, addr_text[INET_ADDRSTRLEN]; size_t size, len, index, padding, addr_len; @@ -422,6 +433,7 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) struct sockaddr_in sin; ngx_http_variable_t *var; ngx_http_variable_value_t *value; + ngx_http_core_loc_conf_t *clcf; ngx_http_core_main_conf_t *cmcf; ngx_http_fastcgi_header_t *h; ngx_http_fastcgi_loc_conf_t *flcf; @@ -450,6 +462,12 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) return NGX_ERROR; } +#if (NGX_SUPPRESS_WARN) + clcf = NULL; + var = NULL; + vindex = NULL; +#endif + if (r->upstream->method) { len = 1 + 1 + sizeof("REQUEST_METHOD") - 1 @@ -496,6 +514,12 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len; } + if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) { + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + len += 1 + ((clcf->root.len > 127) ? 4 : 1) + + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len; + } + if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) { len += 1 + ((r->uri.len + index > 127) ? 4 : 1) + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ; @@ -533,19 +557,21 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) } - cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); + if (flcf->vars) { + cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); - var = cmcf->variables.elts; - vindex = flcf->vars.elts; + var = cmcf->variables.elts; + vindex = flcf->vars->elts; - for (i = 0; i < flcf->vars.nelts; i++) { + for (i = 0; i < flcf->vars->nelts; i++) { - if (!(value = ngx_http_get_variable(r, vindex[i]))) { - continue; - } + if (!(value = ngx_http_get_variable(r, vindex[i]))) { + continue; + } - if (value->text.len) { - len += 1 + 1 + var[vindex[i]].name.len + value->text.len; + if (value->text.len) { + len += 1 + 1 + var[vindex[i]].name.len + value->text.len; + } } } @@ -785,6 +811,26 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) } + if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) { + *b->last++ = sizeof("DOCUMENT_ROOT") - 1; + + len = clcf->root.len; + if (len > 127) { + *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); + *b->last++ = (u_char) ((len >> 16) & 0xff); + *b->last++ = (u_char) ((len >> 8) & 0xff); + *b->last++ = (u_char) (len & 0xff); + + } else { + *b->last++ = (u_char) len; + } + + b->last = ngx_cpymem(b->last, "DOCUMENT_ROOT", + sizeof("DOCUMENT_ROOT") - 1); + b->last = ngx_cpymem(b->last, clcf->root.data, len); + } + + if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) { *b->last++ = sizeof("SCRIPT_NAME") - 1; @@ -882,23 +928,25 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) } - for (i = 0; i < flcf->vars.nelts; i++) { + if (flcf->vars) { + for (i = 0; i < flcf->vars->nelts; i++) { - if (!(value = ngx_http_get_variable(r, vindex[i]))) { - continue; - } + if (!(value = ngx_http_get_variable(r, vindex[i]))) { + continue; + } - if (value->text.len == 0) { - continue; - } + if (value->text.len == 0) { + continue; + } - *b->last++ = (u_char) var[vindex[i]].name.len; - *b->last++ = (u_char) value->text.len; + *b->last++ = (u_char) var[vindex[i]].name.len; + *b->last++ = (u_char) value->text.len; - b->last = ngx_cpymem(b->last, var[vindex[i]].name.data, - var[vindex[i]].name.len); + b->last = ngx_cpymem(b->last, var[vindex[i]].name.data, + var[vindex[i]].name.len); - b->last = ngx_cpymem(b->last, value->text.data, value->text.len); + b->last = ngx_cpymem(b->last, value->text.data, value->text.len); + } } @@ -1091,7 +1139,8 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r) } -static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r) +static ngx_int_t +ngx_http_fastcgi_reinit_request(ngx_http_request_t *r) { ngx_http_fastcgi_ctx_t *f; @@ -1357,7 +1406,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r) } -static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r) +static ngx_int_t +ngx_http_fastcgi_send_header(ngx_http_request_t *r) { ngx_uint_t i; ngx_list_part_t *part; @@ -1433,8 +1483,8 @@ static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r) } -static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, - ngx_buf_t *buf) +static ngx_int_t +ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) { ngx_int_t rc; ngx_buf_t *b, **prev; @@ -1637,8 +1687,9 @@ static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, } -static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r, - ngx_http_fastcgi_ctx_t *f) +static ngx_int_t +ngx_http_fastcgi_process_record(ngx_http_request_t *r, + ngx_http_fastcgi_ctx_t *f) { u_char ch, *p; ngx_http_upstream_t *u; @@ -1746,7 +1797,8 @@ static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r, } -static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r) +static void +ngx_http_fastcgi_abort_request(ngx_http_request_t *r) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "abort http fastcgi request"); @@ -1755,8 +1807,8 @@ static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r) } -static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, - ngx_int_t rc) +static void +ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "finalize http fastcgi request"); @@ -1765,8 +1817,8 @@ static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, } -static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_fastcgi_loc_conf_t *lcf = conf; @@ -1829,8 +1881,8 @@ static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_fastcgi_loc_conf_t *lcf = conf; @@ -1839,10 +1891,10 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, ngx_http_variable_t *var; ngx_http_core_main_conf_t *cmcf; - if (lcf->vars.elts == NULL) { - if (ngx_array_init(&lcf->vars, cf->pool, 4, - sizeof(ngx_http_variable_t *)) == NGX_ERROR) - { + if (lcf->vars == NULL) { + lcf->vars = ngx_array_create(cf->pool, 4, + sizeof(ngx_http_variable_t *)); + if (lcf->vars == NULL) { return NGX_CONF_ERROR; } } @@ -1855,7 +1907,7 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, for (i = 0; i < cmcf->variables.nelts; i++) { if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { - if (!(index = ngx_array_push(&lcf->vars))) { + if (!(index = ngx_array_push(lcf->vars))) { return NGX_CONF_ERROR; } @@ -1870,8 +1922,8 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, - void *data) +static char * +ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data) { #if (NGX_FREEBSD) ssize_t *np = data; @@ -1899,7 +1951,8 @@ static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, } -static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) +static void * +ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) { ngx_http_fastcgi_loc_conf_t *conf; @@ -1933,6 +1986,7 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) conf->upstream.max_temp_file_size = NGX_CONF_UNSET_SIZE; conf->upstream.temp_file_write_size = NGX_CONF_UNSET_SIZE; + conf->upstream.redirect_errors = NGX_CONF_UNSET; conf->upstream.x_powered_by = NGX_CONF_UNSET; /* "fastcgi_cyclic_temp_file" is disabled */ @@ -1942,8 +1996,8 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) } -static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, - void *parent, void *child) +static char * +ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_fastcgi_loc_conf_t *prev = parent; ngx_http_fastcgi_loc_conf_t *conf = child; @@ -1960,6 +2014,9 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_msec_value(conf->upstream.read_timeout, prev->upstream.read_timeout, 60000); + ngx_conf_merge_msec_value(conf->upstream.redirect_errors, + prev->upstream.redirect_errors, 0); + ngx_conf_merge_msec_value(conf->upstream.x_powered_by, prev->upstream.x_powered_by, 1); @@ -2049,10 +2106,10 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, - prev->upstream.next_upstream, - (NGX_CONF_BITMASK_SET - |NGX_HTTP_UPSTREAM_FT_ERROR - |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); + prev->upstream.next_upstream, + (NGX_CONF_BITMASK_SET + |NGX_HTTP_UPSTREAM_FT_ERROR + |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); ngx_conf_merge_path_value(conf->upstream.temp_path, prev->upstream.temp_path, @@ -2061,15 +2118,15 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_bitmask_value(conf->params, prev->params, - (NGX_CONF_BITMASK_SET - |NGX_HTTP_FASTCGI_REMOTE_ADDR - |NGX_HTTP_FASTCGI_REMOTE_USER - |NGX_HTTP_FASTCGI_SERVER_NAME - |NGX_HTTP_FASTCGI_SERVER_PORT - |NGX_HTTP_FASTCGI_SCRIPT_NAME - |NGX_HTTP_FASTCGI_AUTH_TYPE - |NGX_HTTP_FASTCGI_REQUEST_URI - |NGX_HTTP_FASTCGI_REDIRECT_STATUS)); + (NGX_CONF_BITMASK_SET + |NGX_HTTP_FASTCGI_REMOTE_ADDR + |NGX_HTTP_FASTCGI_REMOTE_USER + |NGX_HTTP_FASTCGI_SERVER_NAME + |NGX_HTTP_FASTCGI_SERVER_PORT + |NGX_HTTP_FASTCGI_SCRIPT_NAME + |NGX_HTTP_FASTCGI_AUTH_TYPE + |NGX_HTTP_FASTCGI_REQUEST_URI + |NGX_HTTP_FASTCGI_REDIRECT_STATUS)); ngx_conf_merge_str_value(conf->root, prev->root, ""); @@ -2079,5 +2136,9 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_str_value(conf->index, prev->index, ""); + if (conf->vars == NULL) { + conf->vars = prev->vars; + } + return NGX_CONF_OK; } diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c index cd774894c..7d17f03ca 100644 --- a/src/http/modules/ngx_http_geo_module.c +++ b/src/http/modules/ngx_http_geo_module.c @@ -91,7 +91,7 @@ static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - if (!(tree = ngx_radix_tree_create(cf->pool))) { + if (!(tree = ngx_radix_tree_create(cf->pool, 8))) { return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c index b1f591c97..d3c721fda 100644 --- a/src/http/modules/ngx_http_rewrite_handler.c +++ b/src/http/modules/ngx_http_rewrite_handler.c @@ -47,6 +47,7 @@ typedef struct { uintptr_t args:1; uintptr_t redirect:1; + uintptr_t break_cycle:1; ngx_str_t name; } ngx_http_rewrite_regex_code_t; @@ -121,18 +122,18 @@ struct ngx_http_rewrite_engine_s { static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle); static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, - void *parent, void *child); + void *parent, void *child); static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); -static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); +static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, + ngx_command_t *cmd, void *conf); static void *ngx_http_rewrite_start_code(ngx_pool_t *pool, - ngx_array_t **codes, size_t size); + ngx_array_t **codes, size_t size); static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, - u_char **main); + void *code); static ngx_command_t ngx_http_rewrite_commands[] = { @@ -208,7 +209,8 @@ ngx_module_t ngx_http_rewrite_module = { uintptr_t ngx_http_rewrite_exit_code = (uintptr_t) NULL; -static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) +static ngx_int_t +ngx_http_rewrite_handler(ngx_http_request_t *r) { ngx_http_rewrite_code_pt code; ngx_http_rewrite_engine_t *e; @@ -259,7 +261,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) } -static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e) { ngx_int_t rc; ngx_uint_t n; @@ -318,7 +321,9 @@ static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e) e->buf.len = code->size; if (code->uri) { - r->uri_changed = 1; + if (!code->break_cycle) { + r->uri_changed = 1; + } if (rc && (r->quoted_uri || r->plus_in_uri)) { e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, @@ -348,7 +353,8 @@ static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e) { ngx_http_request_t *r; ngx_http_rewrite_regex_end_code_t *code; @@ -377,7 +383,7 @@ static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e) } else { if (code->args && r->args.len) { - *e->pos++ = '&'; + *e->pos++ = '?'; e->pos = ngx_cpymem(e->pos, r->args.data, r->args.len); } @@ -425,7 +431,8 @@ static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e) { ngx_http_rewrite_copy_capture_code_t *code; @@ -450,7 +457,8 @@ static void ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e) { ngx_http_rewrite_copy_code_t *code; @@ -467,7 +475,8 @@ static void ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, "http rewrite args"); @@ -477,7 +486,8 @@ static void ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e) { ngx_http_rewrite_return_code_t *code; @@ -489,7 +499,8 @@ static void ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e) { ngx_http_rewrite_if_code_t *code; @@ -514,7 +525,8 @@ static void ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e) { ngx_http_variable_value_t *value; ngx_http_rewrite_var_code_t *code; @@ -540,7 +552,8 @@ static void ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e) { u_char *ref; size_t len; @@ -625,13 +638,15 @@ static void ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e) } -static void ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e) +static void +ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e) { e->ip += sizeof(uintptr_t); } -static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle) +static ngx_int_t +ngx_http_rewrite_init(ngx_cycle_t *cycle) { ngx_http_handler_pt *h; ngx_http_core_main_conf_t *cmcf; @@ -649,7 +664,8 @@ static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle) } -static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf) +static void * +ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf) { ngx_http_rewrite_loc_conf_t *conf; @@ -665,8 +681,8 @@ static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf) } -static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, - void *parent, void *child) +static char * +ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_rewrite_loc_conf_t *prev = parent; ngx_http_rewrite_loc_conf_t *conf = child; @@ -737,7 +753,8 @@ static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, } -static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +static char * +ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rewrite_loc_conf_t *lcf = conf; @@ -793,6 +810,10 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (ngx_strcmp(value[3].data, "last") == 0) { last = 1; + } else if (ngx_strcmp(value[3].data, "break") == 0) { + regex->break_cycle = 1; + last = 1; + } else if (ngx_strcmp(value[3].data, "redirect") == 0) { regex->status = NGX_HTTP_MOVED_TEMPORARILY; regex->redirect = 1; @@ -824,7 +845,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) copy_capture = ngx_http_rewrite_add_code(lcf->codes, sizeof(ngx_http_rewrite_copy_capture_code_t), - (u_char **) ®ex); + ®ex); if (copy_capture == NULL) { return NGX_CONF_ERROR; } @@ -857,7 +878,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (!regex->redirect) { code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t), - (u_char **) ®ex); + ®ex); if (code == NULL) { return NGX_CONF_ERROR; } @@ -907,7 +928,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) copy = ngx_http_rewrite_add_code(lcf->codes, sizeof(ngx_http_rewrite_copy_code_t) + size, - (u_char **) ®ex); + ®ex); if (copy == NULL) { return NGX_CONF_ERROR; } @@ -939,7 +960,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) regex_end = ngx_http_rewrite_add_code(lcf->codes, sizeof(ngx_http_rewrite_regex_end_code_t), - (u_char **) ®ex); + ®ex); if (regex_end == NULL) { return NGX_CONF_ERROR; } @@ -951,7 +972,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (last) { code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t), - (u_char **) ®ex); + ®ex); if (code == NULL) { return NGX_CONF_ERROR; } @@ -966,9 +987,8 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } - -static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rewrite_loc_conf_t *lcf = conf; @@ -996,7 +1016,8 @@ static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +static char * +ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rewrite_loc_conf_t *lcf = conf; @@ -1179,8 +1200,8 @@ static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } -static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rewrite_loc_conf_t *lcf = conf; @@ -1266,8 +1287,8 @@ static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, } -static void *ngx_http_rewrite_start_code(ngx_pool_t *pool, - ngx_array_t **codes, size_t size) +static void * +ngx_http_rewrite_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) { if (*codes == NULL) { if (!(*codes = ngx_array_create(pool, 256, 1))) { @@ -1279,10 +1300,10 @@ static void *ngx_http_rewrite_start_code(ngx_pool_t *pool, } -static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, - u_char **main) +static void * +ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, void *code) { - u_char *elts; + u_char *elts, **p; void *new; elts = codes->elts; @@ -1292,7 +1313,8 @@ static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, } if (elts != codes->elts) { - *main += (u_char *) codes->elts - elts; + p = code; + *p += (u_char *) codes->elts - elts; } return new; diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c new file mode 100644 index 000000000..3a35fe910 --- /dev/null +++ b/src/http/modules/ngx_http_stub_status_module.c @@ -0,0 +1,138 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_http.h> + + +static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); + +static ngx_command_t ngx_http_status_commands[] = { + + { ngx_string("stub_status"), + NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_http_set_status, + 0, + 0, + NULL }, + + ngx_null_command +}; + + + +ngx_http_module_t ngx_http_stub_status_module_ctx = { + NULL, /* pre conf */ + + NULL, /* create main configuration */ + NULL, /* init main configuration */ + + NULL, /* create server configuration */ + NULL, /* merge server configuration */ + + NULL, /* create location configuration */ + NULL /* merge location configuration */ +}; + + +ngx_module_t ngx_http_stub_status_module = { + NGX_MODULE, + &ngx_http_stub_status_module_ctx, /* module context */ + ngx_http_status_commands, /* module directives */ + NGX_HTTP_MODULE, /* module type */ + NULL, /* init module */ + NULL /* init process */ +}; + + +static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r) +{ + size_t size; + ngx_int_t rc; + uint32_t ap, hn, ac, rq, rd, wr; + ngx_buf_t *b; + ngx_chain_t out; + + if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { + return NGX_HTTP_NOT_ALLOWED; + } + + rc = ngx_http_discard_body(r); + + if (rc != NGX_OK && rc != NGX_AGAIN) { + return rc; + } + + r->headers_out.content_type = ngx_list_push(&r->headers_out.headers); + if (r->headers_out.content_type == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + r->headers_out.content_type->key.len = 0; + r->headers_out.content_type->key.data = NULL; + r->headers_out.content_type->value.len = sizeof("text/plain") - 1; + r->headers_out.content_type->value.data = (u_char *) "text/plain"; + + if (r->method == NGX_HTTP_HEAD) { + r->headers_out.status = NGX_HTTP_OK; + + rc = ngx_http_send_header(r); + + if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { + return rc; + } + } + + size = sizeof("Active connections: \n") + NGX_INT32_LEN + + sizeof("server accepts handled requests\n") - 1 + + 6 + 3 * NGX_INT32_LEN + + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_INT32_LEN; + + if (!(b = ngx_create_temp_buf(r->pool, size))) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + out.buf = b; + out.next = NULL; + + ap = *ngx_stat_accepted; + hn = *ngx_connection_counter; + ac = *ngx_stat_active; + rq = *ngx_stat_requests; + rd = *ngx_stat_reading; + wr = *ngx_stat_writing; + + b->last = ngx_sprintf(b->last, "Active connections: %d \n", ac); + + b->last = ngx_cpymem(b->last, "server accepts handled requests\n", + sizeof("server accepts handled requests\n") - 1); + + b->last = ngx_sprintf(b->last, " %d %d %d \n", ap, hn, rq); + + b->last = ngx_sprintf(b->last, "Reading: %d Writing: %d Waiting: %d \n", + rd, wr, ac - (rd + wr)); + + r->headers_out.status = NGX_HTTP_OK; + r->headers_out.content_length_n = b->last - b->pos; + + b->last_buf = 1; + + rc = ngx_http_send_header(r); + + if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { + return rc; + } + + return ngx_http_output_filter(r, &out);; +} + + +static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_http_core_loc_conf_t *clcf; + + clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); + clcf->handler = ngx_http_status_handler; + + return NGX_CONF_OK; +} diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index a195b45e4..d213d6929 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -1284,6 +1284,10 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_value(conf->lm_factor, prev->lm_factor, 0); ngx_conf_merge_sec_value(conf->default_expires, prev->default_expires, 0); + if (conf->x_vars == NULL) { + conf->x_vars = prev->x_vars; + } + return NULL; } @@ -1389,10 +1393,10 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd, ngx_http_variable_t *var; ngx_http_core_main_conf_t *cmcf; - if (lcf->x_vars.elts == NULL) { - if (ngx_array_init(&lcf->x_vars, cf->pool, 4, - sizeof(ngx_http_variable_t *)) == NGX_ERROR) - { + if (lcf->x_vars == NULL) { + lcf->x_vars = ngx_array_create(cf->pool, 4, + sizeof(ngx_http_variable_t *)); + if (lcf->x_vars == NULL) { return NGX_CONF_ERROR; } } @@ -1405,7 +1409,7 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd, for (i = 0; i < cmcf->variables.nelts; i++) { if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { - if (!(index = ngx_array_push(&lcf->x_vars))) { + if (!(index = ngx_array_push(lcf->x_vars))) { return NGX_CONF_ERROR; } diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index 28d7971df..f950258dc 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -87,7 +87,7 @@ typedef struct { ngx_path_t *cache_path; ngx_path_t *temp_path; - ngx_array_t x_vars; + ngx_array_t *x_vars; ngx_http_busy_lock_t *busy_lock; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index cf5195368..e2fe01554 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -100,6 +100,11 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) r = p->request; uc = p->lcf->upstream; +#if (NGX_SUPPRESS_WARN) + var = NULL; + index = NULL; +#endif + if (p->upstream->method) { len = http_methods[p->upstream->method - 1].len; @@ -169,20 +174,22 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) } - cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); + if (p->lcf->x_vars) { + cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); - var = cmcf->variables.elts; - index = p->lcf->x_vars.elts; + var = cmcf->variables.elts; + index = p->lcf->x_vars->elts; - for (i = 0; i < p->lcf->x_vars.nelts; i++) { + for (i = 0; i < p->lcf->x_vars->nelts; i++) { - if (!(value = ngx_http_get_variable(r, index[i]))) { - continue; - } + if (!(value = ngx_http_get_variable(r, index[i]))) { + continue; + } - if (value->text.len) { - len += sizeof("X-") - 1 + var[index[i]].name.len + sizeof(": ") - 1 - + value->text.len + sizeof(CRLF) - 1; + if (value->text.len) { + len += sizeof("X-") - 1 + var[index[i]].name.len + + sizeof(": ") - 1 + value->text.len + sizeof(CRLF) - 1; + } } } @@ -356,26 +363,28 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) } - for (i = 0; i < p->lcf->x_vars.nelts; i++) { + if (p->lcf->x_vars) { + for (i = 0; i < p->lcf->x_vars->nelts; i++) { - if (!(value = ngx_http_get_variable(r, index[i]))) { - continue; - } + if (!(value = ngx_http_get_variable(r, index[i]))) { + continue; + } - if (value->text.len == 0) { - continue; - } + if (value->text.len == 0) { + continue; + } - *b->last++ = 'X'; *b->last++ = '-'; + *b->last++ = 'X'; *b->last++ = '-'; - b->last = ngx_cpymem(b->last, var[index[i]].name.data, - var[index[i]].name.len); + b->last = ngx_cpymem(b->last, var[index[i]].name.data, + var[index[i]].name.len); - *b->last++ = ':'; *b->last++ = ' '; + *b->last++ = ':'; *b->last++ = ' '; - b->last = ngx_cpymem(b->last, value->text.data, value->text.len); + b->last = ngx_cpymem(b->last, value->text.data, value->text.len); - *b->last++ = CR; *b->last++ = LF; + *b->last++ = CR; *b->last++ = LF; + } } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 10fcb8790..8b66a7911 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -20,39 +20,39 @@ static void ngx_http_core_phase_event_handler(ngx_event_t *rev); static void ngx_http_core_run_phases(ngx_http_request_t *r); static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, - ngx_array_t *locations, size_t len); + ngx_array_t *locations, size_t len); static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, - void *parent, void *child); + void *parent, void *child); static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, - void *parent, void *child); + void *parent, void *child); static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, - void *dummy); + void *dummy); static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, - void *dummy); + void *dummy); static int ngx_http_core_cmp_locations(const void *first, const void *second); static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, - void *conf); + void *conf); static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); @@ -360,7 +360,8 @@ ngx_module_t ngx_http_core_module = { }; -void ngx_http_handler(ngx_http_request_t *r) +void +ngx_http_handler(ngx_http_request_t *r) { r->connection->log->action = NULL; @@ -416,12 +417,11 @@ void ngx_http_handler(ngx_http_request_t *r) r->uri_changes = 11; ngx_http_core_run_phases(r); - - return; } -static void ngx_http_core_phase_event_handler(ngx_event_t *ev) +static void +ngx_http_core_phase_event_handler(ngx_event_t *ev) { ngx_connection_t *c; ngx_http_request_t *r; @@ -432,12 +432,11 @@ static void ngx_http_core_phase_event_handler(ngx_event_t *ev) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler"); ngx_http_core_run_phases(r); - - return; } -static void ngx_http_core_run_phases(ngx_http_request_t *r) +static void +ngx_http_core_run_phases(ngx_http_request_t *r) { ngx_int_t rc; ngx_http_handler_pt *h; @@ -541,11 +540,11 @@ static void ngx_http_core_run_phases(ngx_http_request_t *r) ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found"); ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND); - return; } -ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r) +ngx_int_t +ngx_http_find_location_config(ngx_http_request_t *r) { ngx_int_t rc; ngx_http_core_loc_conf_t *clcf; @@ -618,8 +617,9 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r) } -static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, - ngx_array_t *locations, size_t len) +static ngx_int_t +ngx_http_core_find_location(ngx_http_request_t *r, + ngx_array_t *locations, size_t len) { ngx_int_t n, rc; ngx_uint_t i, found, noregex; @@ -752,7 +752,8 @@ static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, } -ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) +ngx_int_t +ngx_http_set_content_type(ngx_http_request_t *r) { u_char c, *p, *exten; uint32_t key; @@ -832,7 +833,8 @@ ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) } -ngx_int_t ngx_http_send_header(ngx_http_request_t *r) +ngx_int_t +ngx_http_send_header(ngx_http_request_t *r) { if (r->main) { return NGX_OK; @@ -843,11 +845,12 @@ ngx_int_t ngx_http_send_header(ngx_http_request_t *r) r->headers_out.status_line.len = 0; } - return (*ngx_http_top_header_filter)(r); + return ngx_http_top_header_filter(r); } -ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) +ngx_int_t +ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_int_t rc; @@ -859,7 +862,7 @@ ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) if (rc == NGX_ERROR) { - /* NGX_ERROR could be returned by any filter */ + /* NGX_ERROR may be returned by any filter */ r->connection->write->error = 1; } @@ -868,7 +871,8 @@ ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) } -int ngx_http_redirect(ngx_http_request_t *r, int redirect) +ngx_int_t +ngx_http_redirect(ngx_http_request_t *r, int redirect) { /* STUB */ @@ -879,7 +883,8 @@ int ngx_http_redirect(ngx_http_request_t *r, int redirect) } -ngx_int_t ngx_http_set_exten(ngx_http_request_t *r) +ngx_int_t +ngx_http_set_exten(ngx_http_request_t *r) { ngx_int_t i; @@ -912,9 +917,12 @@ ngx_int_t ngx_http_set_exten(ngx_http_request_t *r) } -ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, - ngx_str_t *uri, ngx_str_t *args) +ngx_int_t +ngx_http_internal_redirect(ngx_http_request_t *r, + ngx_str_t *uri, ngx_str_t *args) { + ngx_http_core_srv_conf_t *cscf; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "internal redirect: \"%V\"", uri); @@ -930,7 +938,7 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, if (r->err_ctx) { - /* allocate the new modules contexts */ + /* allocate the new module's contexts */ r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); if (r->ctx == NULL) { @@ -944,6 +952,9 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); } + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + r->loc_conf = cscf->ctx->loc_conf; + r->phase = 0; r->phase_handler = 0; r->content_handler = NULL; @@ -956,7 +967,8 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, #if 0 /* STUB: test the delay http handler */ -int ngx_http_delay_handler(ngx_http_request_t *r) +ngx_int_t +ngx_http_delay_handler(ngx_http_request_t *r) { static int on; @@ -976,7 +988,8 @@ int ngx_http_delay_handler(ngx_http_request_t *r) #endif -ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf) +ngx_http_variable_t * +ngx_http_add_variable(ngx_conf_t *cf) { ngx_http_variable_t *var; ngx_http_core_main_conf_t *cmcf; @@ -1001,8 +1014,8 @@ ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf) } -ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r, - ngx_uint_t index) +ngx_http_variable_value_t * +ngx_http_get_variable(ngx_http_request_t *r, ngx_uint_t index) { ngx_http_variable_t *v; ngx_http_core_main_conf_t *cmcf; @@ -1023,35 +1036,38 @@ ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r, } -static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, - void *dummy) +static char * +ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) { - int m; - char *rv; - ngx_http_module_t *module; - ngx_conf_t save; - ngx_http_conf_ctx_t *ctx, *http_ctx; - ngx_http_core_main_conf_t *cmcf; - ngx_http_core_srv_conf_t *cscf, **cscfp; - - ngx_test_null(ctx, - ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), - NGX_CONF_ERROR); + int m; + char *rv; + void *mconf; + ngx_conf_t save; + ngx_http_module_t *module; + ngx_http_conf_ctx_t *ctx, *http_ctx; + ngx_http_core_srv_conf_t *cscf, **cscfp; + ngx_http_core_main_conf_t *cmcf; + + if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { + return NGX_CONF_ERROR; + } http_ctx = cf->ctx; ctx->main_conf = http_ctx->main_conf; /* the server{}'s srv_conf */ - ngx_test_null(ctx->srv_conf, - ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), - NGX_CONF_ERROR); + ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); + if (ctx->srv_conf == NULL) { + return NGX_CONF_ERROR; + } /* the server{}'s loc_conf */ - ngx_test_null(ctx->loc_conf, - ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), - NGX_CONF_ERROR); + ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); + if (ctx->loc_conf == NULL) { + return NGX_CONF_ERROR; + } for (m = 0; ngx_modules[m]; m++) { if (ngx_modules[m]->type != NGX_HTTP_MODULE) { @@ -1061,27 +1077,38 @@ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, module = ngx_modules[m]->ctx; if (module->create_srv_conf) { - ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index], - module->create_srv_conf(cf), - NGX_CONF_ERROR); + if (!(mconf = module->create_srv_conf(cf))) { + return NGX_CONF_ERROR; + } + + ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; } if (module->create_loc_conf) { - ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], - module->create_loc_conf(cf), - NGX_CONF_ERROR); + if (!(mconf = module->create_loc_conf(cf))) { + return NGX_CONF_ERROR; + } + + ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf; } } - /* create links of the srv_conf's */ + + /* the server configuration context */ cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; cscf->ctx = ctx; + cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; - ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR); + + if (!(cscfp = ngx_array_push(&cmcf->servers))) { + return NGX_CONF_ERROR; + } + *cscfp = cscf; + /* parse inside server{} */ save = *cf; @@ -1103,8 +1130,8 @@ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, - void *dummy) +static char * +ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) { char *rv; ngx_int_t m; @@ -1205,7 +1232,7 @@ static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, if (pclcf->name.len == 0) { cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; - if (!(clcfp = ngx_push_array(&cscf->locations))) { + if (!(clcfp = ngx_array_push(&cscf->locations))) { return NGX_CONF_ERROR; } @@ -1268,7 +1295,8 @@ static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, } -static int ngx_http_core_cmp_locations(const void *one, const void *two) +static int +ngx_http_core_cmp_locations(const void *one, const void *two) { ngx_int_t rc; ngx_http_core_loc_conf_t *first, *second; @@ -1321,7 +1349,8 @@ static int ngx_http_core_cmp_locations(const void *one, const void *two) } -static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +static char * +ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *rv; ngx_conf_t save; @@ -1338,8 +1367,8 @@ static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } -static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, - void *conf) +static char * +ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; @@ -1381,7 +1410,8 @@ static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, } -static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) +static void * +ngx_http_core_create_main_conf(ngx_conf_t *cf) { ngx_http_core_main_conf_t *cmcf; @@ -1402,7 +1432,8 @@ static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) } -static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) +static char * +ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) { ngx_http_core_main_conf_t *cmcf = conf; @@ -1418,25 +1449,38 @@ static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) } -static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf) +static void * +ngx_http_core_create_srv_conf(ngx_conf_t *cf) { ngx_http_core_srv_conf_t *cscf; - ngx_test_null(cscf, - ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)), - NGX_CONF_ERROR); + if (!(cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)))) { + return NGX_CONF_ERROR; + } + /* - * * set by ngx_pcalloc(): + * * conf->client_large_buffers.num = 0; */ - ngx_init_array(cscf->locations, cf->pool, - 5, sizeof(void *), NGX_CONF_ERROR); - ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), - NGX_CONF_ERROR); - ngx_init_array(cscf->server_names, cf->pool, - 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); + if (ngx_array_init(&cscf->locations, cf->pool, 5, sizeof(void *)) + == NGX_ERROR) + { + return NGX_CONF_ERROR; + } + + if (ngx_array_init(&cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t)) + == NGX_ERROR) + { + return NGX_CONF_ERROR; + } + + if (ngx_array_init(&cscf->server_names, cf->pool, 5, + sizeof(ngx_http_server_name_t)) == NGX_ERROR) + { + return NGX_CONF_ERROR; + } cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC; @@ -1449,49 +1493,56 @@ static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf) } -static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, - void *parent, void *child) +static char * +ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_core_srv_conf_t *prev = parent; ngx_http_core_srv_conf_t *conf = child; - ngx_http_listen_t *l; - ngx_http_server_name_t *n; + ngx_http_listen_t *ls; + ngx_http_server_name_t *sn; ngx_http_core_main_conf_t *cmcf; /* TODO: it does not merge, it inits only */ if (conf->listen.nelts == 0) { - ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); - l->addr = INADDR_ANY; + if (!(ls = ngx_array_push(&conf->listen))) { + return NGX_CONF_ERROR; + } + + ls->addr = INADDR_ANY; #if (NGX_WIN32) - l->port = 80; + ls->port = 80; #else /* STUB: getuid() should be cached */ - l->port = (getuid() == 0) ? 80 : 8000; + ls->port = (getuid() == 0) ? 80 : 8000; #endif - l->family = AF_INET; + ls->family = AF_INET; } if (conf->server_names.nelts == 0) { - ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); - ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), - NGX_CONF_ERROR); + if (!(sn = ngx_array_push(&conf->server_names))) { + return NGX_CONF_ERROR; + } - if (gethostname((char *) n->name.data, NGX_MAXHOSTNAMELEN) == -1) { + if (!(sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN))) { + return NGX_CONF_ERROR; + } + + if (gethostname((char *) sn->name.data, NGX_MAXHOSTNAMELEN) == -1) { ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, "gethostname() failed"); return NGX_CONF_ERROR; } - n->name.len = ngx_strlen(n->name.data); - n->core_srv_conf = conf; - n->wildcard = 0; + sn->name.len = ngx_strlen(sn->name.data); + sn->core_srv_conf = conf; + sn->wildcard = 0; cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); - if (cmcf->max_server_name_len < n->name.len) { - cmcf->max_server_name_len = n->name.len; + if (cmcf->max_server_name_len < sn->name.len) { + cmcf->max_server_name_len = sn->name.len; } } @@ -1517,19 +1568,20 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, } ngx_conf_merge_unsigned_value(conf->restrict_host_names, - prev->restrict_host_names, 0); + prev->restrict_host_names, 0); return NGX_CONF_OK; } -static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) +static void * +ngx_http_core_create_loc_conf(ngx_conf_t *cf) { ngx_http_core_loc_conf_t *lcf; - ngx_test_null(lcf, - ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), - NGX_CONF_ERROR); + if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)))) { + return NGX_CONF_ERROR; + } /* * set by ngx_pcalloc(): @@ -1569,7 +1621,7 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) } -static ngx_http_type_t default_types[] = { +static ngx_http_type_t ngx_http_core_default_types[] = { { ngx_string("html"), ngx_string("text/html") }, { ngx_string("gif"), ngx_string("image/gif") }, { ngx_string("jpg"), ngx_string("image/jpeg") }, @@ -1577,14 +1629,16 @@ static ngx_http_type_t default_types[] = { }; -static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, +static char * +ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_core_loc_conf_t *prev = parent; ngx_http_core_loc_conf_t *conf = child; - int i, key; - ngx_http_type_t *t; + uint32_t key; + ngx_uint_t i; + ngx_http_type_t *type; ngx_conf_merge_str_value(conf->root, prev->root, "html"); @@ -1597,25 +1651,29 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, conf->types = prev->types; } else { - ngx_test_null(conf->types, - ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME - * sizeof(ngx_array_t)), - NGX_CONF_ERROR); + conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME + * sizeof(ngx_array_t)); + if (conf->types == NULL) { + return NGX_CONF_ERROR; + } for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { - ngx_init_array(conf->types[i], cf->pool, - 5, sizeof(ngx_http_type_t), NGX_CONF_ERROR); + if (ngx_array_init(&conf->types[i], cf->pool, 5, + sizeof(ngx_http_type_t)) == NGX_ERROR) + { + return NGX_CONF_ERROR; + } } - for (i = 0; default_types[i].exten.len; i++) { - ngx_http_types_hash_key(key, default_types[i].exten); + for (i = 0; ngx_http_core_default_types[i].exten.len; i++) { + ngx_http_types_hash_key(key, + ngx_http_core_default_types[i].exten); - ngx_test_null(t, ngx_push_array(&conf->types[key]), - NGX_CONF_ERROR); - t->exten.len = default_types[i].exten.len; - t->exten.data = default_types[i].exten.data; - t->type.len = default_types[i].type.len; - t->type.data = default_types[i].type.data; + if (!(type = ngx_array_push(&conf->types[key]))) { + return NGX_CONF_ERROR; + } + + *type = ngx_http_core_default_types[i]; } } } @@ -1633,7 +1691,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, } ngx_conf_merge_str_value(conf->default_type, - prev->default_type, "text/plain"); + prev->default_type, "text/plain"); ngx_conf_merge_size_value(conf->client_max_body_size, prev->client_max_body_size, 1 * 1024 * 1024); @@ -1665,7 +1723,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, ngx_garbage_collector_temp_handler, cf); ngx_conf_merge_value(conf->reset_timedout_connection, - prev->reset_timedout_connection, 0); + prev->reset_timedout_connection, 0); ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); if (conf->open_files == NULL) { @@ -1676,8 +1734,8 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, } -static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_srv_conf_t *scf = conf; @@ -1746,6 +1804,7 @@ static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, } ls->addr = inet_addr((const char *) addr); + if (ls->addr == INADDR_NONE) { h = gethostbyname((const char *) addr); @@ -1763,8 +1822,8 @@ static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_srv_conf_t *scf = conf; @@ -1814,7 +1873,8 @@ static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +static char * +ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; @@ -1854,18 +1914,18 @@ static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } -static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; - int overwrite; + ngx_int_t overwrite; ngx_uint_t i, n; ngx_str_t *value; ngx_http_err_page_t *err; if (lcf->error_pages == NULL) { - lcf->error_pages = ngx_create_array(cf->pool, 5, + lcf->error_pages = ngx_array_create(cf->pool, 4, sizeof(ngx_http_err_page_t)); if (lcf->error_pages == NULL) { return NGX_CONF_ERROR; @@ -1899,11 +1959,12 @@ static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, } for (i = 1; i < cf->args->nelts - n; i++) { - if (!(err = ngx_push_array(lcf->error_pages))) { + if (!(err = ngx_array_push(lcf->error_pages))) { return NGX_CONF_ERROR; } err->status = ngx_atoi(value[i].data, value[i].len); + if (err->status == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%V\"", &value[i]); @@ -1925,8 +1986,8 @@ static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; @@ -1939,6 +2000,7 @@ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, value = cf->args->elts; lcf->keepalive_timeout = ngx_parse_time(&value[1], 0); + if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { return "invalid value"; } @@ -1952,6 +2014,7 @@ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, } lcf->keepalive_header = ngx_parse_time(&value[2], 1); + if (lcf->keepalive_header == NGX_ERROR) { return "invalid value"; } @@ -1964,8 +2027,8 @@ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; @@ -1977,7 +2040,8 @@ static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) +static char * +ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) { #if (NGX_FREEBSD) ssize_t *np = data; diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c index d4f906f1a..722b9f806 100644 --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -859,7 +859,10 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, } } - return NGX_CONF_OK; + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "unknown log format \"%V\"", &name); + + return NGX_CONF_ERROR; } diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index 5702a855a..a26937497 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -193,7 +193,8 @@ static ngx_str_t error_pages[] = { }; -ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r, int error) +ngx_int_t +ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error) { ngx_int_t rc; ngx_uint_t err, i, msie_padding; diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 11e0f3105..5b8312130 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -12,29 +12,26 @@ static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev); static void ngx_http_upstream_connect(ngx_http_request_t *r, - ngx_http_upstream_t *u); + ngx_http_upstream_t *u); static void ngx_http_upstream_reinit(ngx_http_request_t *r, - ngx_http_upstream_t *u); + ngx_http_upstream_t *u); static void ngx_http_upstream_send_request(ngx_http_request_t *r, - ngx_http_upstream_t *u); + ngx_http_upstream_t *u); static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); static void 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); + ngx_http_upstream_t *u); static void ngx_http_upstream_process_body(ngx_event_t *ev); static void ngx_http_upstream_dummy_handler(ngx_event_t *wev); static void ngx_http_upstream_next(ngx_http_request_t *r, - ngx_http_upstream_t *u, - ngx_uint_t ft_type); + ngx_http_upstream_t *u, ngx_uint_t ft_type); static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, - ngx_http_upstream_t *u, - ngx_int_t rc); + ngx_http_upstream_t *u, ngx_int_t rc); static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); - + uintptr_t data); +static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, + u_char *buf, ngx_http_log_op_t *op); static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf); @@ -77,7 +74,8 @@ char *ngx_http_upstream_header_errors[] = { }; -void ngx_http_upstream_init(ngx_http_request_t *r) +void +ngx_http_upstream_init(ngx_http_request_t *r) { ngx_connection_t *c; ngx_http_upstream_t *u; @@ -148,7 +146,8 @@ void ngx_http_upstream_init(ngx_http_request_t *r) } -static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev) +static void +ngx_http_upstream_check_broken_connection(ngx_event_t *ev) { int n; char buf[1]; @@ -265,8 +264,8 @@ static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev) } -static void ngx_http_upstream_connect(ngx_http_request_t *r, - ngx_http_upstream_t *u) +static void +ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) { ngx_int_t rc; ngx_connection_t *c; @@ -350,8 +349,8 @@ static void ngx_http_upstream_connect(ngx_http_request_t *r, } -static void ngx_http_upstream_reinit(ngx_http_request_t *r, - ngx_http_upstream_t *u) +static void +ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) { ngx_chain_t *cl; @@ -400,14 +399,11 @@ static void ngx_http_upstream_reinit(ngx_http_request_t *r, } ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); - - u->status = 0; - u->status_count = 0; } -static void ngx_http_upstream_send_request(ngx_http_request_t *r, - ngx_http_upstream_t *u) +static void +ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u) { int rc; ngx_connection_t *c; @@ -505,7 +501,8 @@ static void ngx_http_upstream_send_request(ngx_http_request_t *r, } -static void ngx_http_upstream_send_request_handler(ngx_event_t *wev) +static void +ngx_http_upstream_send_request_handler(ngx_event_t *wev) { ngx_connection_t *c; ngx_http_request_t *r; @@ -534,13 +531,17 @@ static void ngx_http_upstream_send_request_handler(ngx_event_t *wev) } -static void ngx_http_upstream_process_header(ngx_event_t *rev) +static void +ngx_http_upstream_process_header(ngx_event_t *rev) { - ssize_t n; - ngx_int_t rc; - ngx_connection_t *c; - ngx_http_request_t *r; - ngx_http_upstream_t *u; + ssize_t n; + ngx_int_t rc; + ngx_uint_t i; + ngx_connection_t *c; + ngx_http_request_t *r; + ngx_http_upstream_t *u; + ngx_http_err_page_t *err_page; + ngx_http_core_loc_conf_t *clcf; c = rev->data; r = c->data; @@ -657,12 +658,31 @@ static void ngx_http_upstream_process_header(ngx_event_t *rev) /* rc == NGX_OK */ + if (r->headers_out.status >= NGX_HTTP_BAD_REQUEST + && u->conf->redirect_errors + && r->err_ctx == NULL) + { + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + if (clcf->error_pages) { + + err_page = clcf->error_pages->elts; + for (i = 0; i < clcf->error_pages->nelts; i++) { + if (err_page[i].status == (ngx_int_t) r->headers_out.status) { + ngx_http_upstream_finalize_request(r, u, + r->headers_out.status); + return; + } + } + } + } + ngx_http_upstream_send_response(r, u); } -static void ngx_http_upstream_send_response(ngx_http_request_t *r, - ngx_http_upstream_t *u) +static void +ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) { ngx_int_t rc; ngx_event_pipe_t *p; @@ -802,7 +822,8 @@ static void ngx_http_upstream_send_response(ngx_http_request_t *r, } -static void ngx_http_upstream_process_body(ngx_event_t *ev) +static void +ngx_http_upstream_process_body(ngx_event_t *ev) { ngx_connection_t *c; ngx_http_request_t *r; @@ -891,16 +912,17 @@ static void ngx_http_upstream_process_body(ngx_event_t *ev) } -static void ngx_http_upstream_dummy_handler(ngx_event_t *wev) +static void +ngx_http_upstream_dummy_handler(ngx_event_t *wev) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http upstream dummy handler"); } -static void ngx_http_upstream_next(ngx_http_request_t *r, - ngx_http_upstream_t *u, - ngx_uint_t ft_type) +static void +ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, + ngx_uint_t ft_type) { ngx_uint_t status; @@ -994,9 +1016,9 @@ static void ngx_http_upstream_next(ngx_http_request_t *r, } -static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, - ngx_http_upstream_t *u, - ngx_int_t rc) +static void +ngx_http_upstream_finalize_request(ngx_http_request_t *r, + ngx_http_upstream_t *u, ngx_int_t rc) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "finalize http upstream request: %i", rc); @@ -1057,8 +1079,8 @@ static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, } -static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, - uintptr_t data) +static size_t +ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data) { if (r->upstream) { return r->upstream->states.nelts * (3 + 2); @@ -1068,8 +1090,9 @@ static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, } -static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) +static u_char * +ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, + ngx_http_log_op_t *op) { ngx_uint_t i; ngx_http_upstream_t *u; @@ -1103,7 +1126,8 @@ static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, } -u_char *ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len) +u_char * +ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len) { u_char *p; ngx_int_t escape; @@ -1177,7 +1201,8 @@ u_char *ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len) } -static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf) +static ngx_int_t +ngx_http_upstream_add_log_formats(ngx_conf_t *cf) { ngx_http_log_op_name_t *op; diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h index 79ba2a194..c722152a2 100644 --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -54,6 +54,7 @@ typedef struct { ngx_bufs_t bufs; + ngx_flag_t redirect_errors; ngx_flag_t x_powered_by; ngx_flag_t cyclic_temp_file; @@ -95,13 +96,6 @@ struct ngx_http_upstream_s { ngx_http_log_ctx_t *saved_log_ctx; ngx_log_handler_pt saved_log_handler; - /* used to parse an upstream HTTP header */ - ngx_uint_t status; - u_char *status_start; - u_char *status_end; - ngx_uint_t status_count; - ngx_uint_t parse_state; - ngx_http_upstream_state_t *state; ngx_array_t states; /* of ngx_http_upstream_state_t */ |