fix case proxy_pass URL is evaluted to http://host?args
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index e976c4c..35638e5 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -251,7 +251,7 @@
static ngx_int_t
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;
ngx_int_t n;
struct hostent *h;
@@ -266,6 +266,17 @@
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 (u->listen || !u->uri_part) {
u->err = "invalid host";
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index f3d747f..83784ea 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -536,10 +536,11 @@
ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
ngx_http_proxy_loc_conf_t *plcf)
{
- size_t add;
- u_short port;
- ngx_str_t proxy;
- ngx_url_t u;
+ u_char *p;
+ size_t add;
+ u_short port;
+ ngx_str_t proxy;
+ ngx_url_t u;
if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0,
plcf->proxy_values->elts)
@@ -589,6 +590,19 @@
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) {
return NGX_ERROR;
}