fix case proxy_pass URL is evaluted to http://host?args

This commit is contained in:
Igor Sysoev 2008-10-24 19:34:24 +00:00
parent c239da5055
commit 164abfb26f
2 changed files with 30 additions and 5 deletions

View File

@ -251,7 +251,7 @@ ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u)
static ngx_int_t static ngx_int_t
ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)
{ {
u_char *p, *host, *port, *last, *uri; u_char *p, *host, *port, *last, *uri, *args;
size_t len; size_t len;
ngx_int_t n; ngx_int_t n;
struct hostent *h; struct hostent *h;
@ -266,6 +266,17 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)
uri = ngx_strlchr(host, last, '/'); uri = ngx_strlchr(host, last, '/');
args = ngx_strlchr(host, last, '?');
if (args) {
if (uri == NULL) {
uri = args;
} else if (args < uri) {
uri = args;
}
}
if (uri) { if (uri) {
if (u->listen || !u->uri_part) { if (u->listen || !u->uri_part) {
u->err = "invalid host"; u->err = "invalid host";

View File

@ -536,10 +536,11 @@ static ngx_int_t
ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
ngx_http_proxy_loc_conf_t *plcf) ngx_http_proxy_loc_conf_t *plcf)
{ {
size_t add; u_char *p;
u_short port; size_t add;
ngx_str_t proxy; u_short port;
ngx_url_t u; ngx_str_t proxy;
ngx_url_t u;
if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0, if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0,
plcf->proxy_values->elts) plcf->proxy_values->elts)
@ -589,6 +590,19 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
return NGX_ERROR; return NGX_ERROR;
} }
if (u.uri.len && u.uri.data[0] == '?') {
p = ngx_pnalloc(r->pool, u.uri.len + 1);
if (p == NULL) {
return NGX_ERROR;
}
*p++ = '/';
ngx_memcpy(p, u.uri.data, u.uri.len);
u.uri.len++;
u.uri.data = p - 1;
}
if (ngx_http_proxy_set_vars(r->pool, &u, &ctx->vars) != NGX_OK) { if (ngx_http_proxy_set_vars(r->pool, &u, &ctx->vars) != NGX_OK) {
return NGX_ERROR; return NGX_ERROR;
} }