diff options
Diffstat (limited to 'src/http/modules/proxy')
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 56 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 1 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 62 |
3 files changed, 76 insertions, 43 deletions
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 2b76c1f9d..9addfc23a 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -107,6 +107,13 @@ static ngx_command_t ngx_http_proxy_commands[] = { offsetof(ngx_http_proxy_loc_conf_t, preserve_host), NULL }, + { ngx_string("proxy_pass_unparsed_uri"), + 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_proxy_loc_conf_t, pass_unparsed_uri), + NULL }, + { ngx_string("proxy_set_x_url"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_flag_slot, @@ -802,7 +809,6 @@ u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) { u_char *p; ngx_int_t escape; - ngx_str_t uri; ngx_http_request_t *r; ngx_peer_connection_t *peer; ngx_http_proxy_log_ctx_t *ctx; @@ -814,7 +820,7 @@ u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) peer = &ctx->proxy->upstream->peer; p = ngx_snprintf(buf, len, - " while %s, client: %V, host: %V, URL: \"%V\"," + " while %s, client: %V, server: %V, URL: \"%V\"," " upstream: http://%V%s%V", ctx->proxy->action, &r->connection->addr_text, @@ -826,6 +832,13 @@ u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) len -= p - buf; buf = p; + if (ctx->proxy->lcf->pass_unparsed_uri && r->valid_unparsed_uri) { + p = ngx_cpymem(buf, r->unparsed_uri.data + 1, r->unparsed_uri.len - 1); + len -= p - buf; + + return ngx_http_log_error_info(r, p, len); + } + if (r->quoted_uri) { escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, r->uri.len - uc->location->len, @@ -841,14 +854,15 @@ u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) r->uri.len - uc->location->len, NGX_ESCAPE_URI); buf += r->uri.len - uc->location->len + escape; + len -= r->uri.len - uc->location->len + escape; - if (r->args.len == 0) { - return buf; + if (r->args.len) { + p = ngx_snprintf(buf, len, "?%V", &r->args); + len -= p - buf; + buf = p; } - len -= r->uri.len - uc->location->len + escape; - - return ngx_snprintf(buf, len, "?%V", &r->args); + return ngx_http_log_error_info(r, buf, len); } p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape); @@ -859,17 +873,23 @@ u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) ngx_escape_uri(p, r->uri.data + uc->location->len, r->uri.len - uc->location->len, NGX_ESCAPE_URI); - uri.len = r->uri.len - uc->location->len + escape; - uri.data = p; + p = ngx_cpymem(buf, p, r->uri.len - uc->location->len + escape); } else { - uri.len = r->uri.len - uc->location->len; - uri.data = r->uri.data + uc->location->len; + p = ngx_cpymem(buf, r->uri.data + uc->location->len, + r->uri.len - uc->location->len); + } + + len -= p - buf; + buf = p; + if (r->args.len) { + p = ngx_snprintf(buf, len, "?%V", &r->args); + len -= p - buf; + buf = p; } - return ngx_snprintf(buf, len, "%V%s%V", - &uri, r->args.len ? "?" : "", &r->args); + return ngx_http_log_error_info(r, buf, len); } @@ -1109,6 +1129,7 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) conf->send_timeout = NGX_CONF_UNSET_MSEC; conf->send_lowat = NGX_CONF_UNSET_SIZE; + conf->pass_unparsed_uri = NGX_CONF_UNSET; conf->preserve_host = NGX_CONF_UNSET; conf->set_x_url = NGX_CONF_UNSET; conf->set_x_real_ip = NGX_CONF_UNSET; @@ -1149,6 +1170,15 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); + ngx_conf_merge_value(conf->pass_unparsed_uri, prev->pass_unparsed_uri, 0); + + if (conf->pass_unparsed_uri && conf->upstream->location->len > 1) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "\"proxy_pass_unparsed_uri\" can be set for " + "location \"/\" or given by regular expression."); + return NGX_CONF_ERROR; + } + ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0); ngx_conf_merge_value(conf->set_x_url, prev->set_x_url, 0); ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index f950258dc..2c9210f9c 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -80,6 +80,7 @@ typedef struct { ngx_flag_t set_x_url; ngx_flag_t set_x_real_ip; ngx_flag_t add_x_forwarded_for; + ngx_flag_t pass_unparsed_uri; ngx_flag_t pass_server; ngx_flag_t pass_x_accel_expires; ngx_flag_t ignore_expires; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 45dc04d70..107aba3df 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -86,7 +86,7 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p) static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) { - size_t len, loc_len; + size_t len; ngx_uint_t i, escape, *index; ngx_buf_t *b; ngx_chain_t *chain; @@ -95,7 +95,6 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) ngx_http_request_t *r; 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_proxy_upstream_conf_t *uc; @@ -107,32 +106,30 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) index = NULL; #endif + escape = 0; + if (p->upstream->method) { - len = http_methods[p->upstream->method - 1].len; + len = http_methods[p->upstream->method - 1].len + uc->uri.len; } else { - len = r->method_name.len; + len = r->method_name.len + uc->uri.len; } - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + if (p->lcf->pass_unparsed_uri && r->valid_unparsed_uri) { + len += r->unparsed_uri.len - 1; -#if (NGX_PCRE) - loc_len = (clcf->regex) ? 1 : clcf->name.len; -#else - loc_len = clcf->name.len; -#endif - - if (r->quoted_uri) { - escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, - r->uri.len - loc_len, NGX_ESCAPE_URI); } else { - escape = 0; + if (r->quoted_uri) { + escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); + } + + len += r->uri.len - uc->location->len + escape + + sizeof("?") - 1 + r->args.len; } - len += uc->uri.len - + r->uri.len - loc_len + escape - + sizeof("?") - 1 + r->args.len - + sizeof(http_version) - 1 + len += sizeof(http_version) - 1 + sizeof(connection_close_header) - 1 + sizeof(CRLF) - 1; @@ -269,19 +266,24 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len); - if (escape) { - ngx_escape_uri(b->last, r->uri.data + loc_len, - r->uri.len - loc_len, NGX_ESCAPE_URI); - b->last += r->uri.len - loc_len + escape; - + if (p->lcf->pass_unparsed_uri && r->valid_unparsed_uri) { + b->last = ngx_cpymem(b->last, r->unparsed_uri.data + 1, + r->unparsed_uri.len - 1); } else { - b->last = ngx_cpymem(b->last, r->uri.data + loc_len, - r->uri.len - loc_len); - } + if (escape) { + ngx_escape_uri(b->last, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + b->last += r->uri.len - uc->location->len + escape; + + } else { + b->last = ngx_cpymem(b->last, r->uri.data + uc->location->len, + r->uri.len - uc->location->len); + } - if (r->args.len > 0) { - *b->last++ = '?'; - b->last = ngx_cpymem(b->last, r->args.data, r->args.len); + if (r->args.len > 0) { + *b->last++ = '?'; + b->last = ngx_cpymem(b->last, r->args.data, r->args.len); + } } b->last = ngx_cpymem(b->last, http_version, sizeof(http_version) - 1); |