summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_parse.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2020-12-10 20:09:30 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2020-12-10 20:09:30 +0300
commitce9971b2b5c14982afede89635508334938ac520 (patch)
tree75d159374284c79ce9c1343f21279b0f701385f7 /src/http/ngx_http_parse.c
parente62a5132ca6ab74f324bf46fe91ee89e1951578c (diff)
downloadnginx-ce9971b2b5c14982afede89635508334938ac520.tar.gz
nginx-ce9971b2b5c14982afede89635508334938ac520.tar.bz2
Fixed parsing of absolute URIs with empty path (ticket #2079).
When the request line contains request-target in the absolute-URI form, it can contain path-empty instead of a single slash (see RFC 7230, RFC 3986). Previously, the ngx_http_parse_request_line() function only accepted empty path when there was no query string. With this change, non-empty query is also correctly handled. That is, request line "GET http://example.com?foo HTTP/1.1" is accepted and results in $uri "/" and $args "foo". Note that $request_uri remains "?foo", similarly to how spaces in URIs are handled. Providing "/?foo", similarly to how "/" is provided for "GET http://example.com HTTP/1.1", requires allocation.
Diffstat (limited to 'src/http/ngx_http_parse.c')
-rw-r--r--src/http/ngx_http_parse.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index cfc42f9dd..20ad89a77 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -380,6 +380,12 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
r->uri_start = p;
state = sw_after_slash_in_uri;
break;
+ case '?':
+ r->uri_start = p;
+ r->args_start = p + 1;
+ r->empty_path_in_uri = 1;
+ state = sw_uri;
+ break;
case ' ':
/*
* use single "/" from request line to preserve pointers,
@@ -446,6 +452,13 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
r->uri_start = p;
state = sw_after_slash_in_uri;
break;
+ case '?':
+ r->port_end = p;
+ r->uri_start = p;
+ r->args_start = p + 1;
+ r->empty_path_in_uri = 1;
+ state = sw_uri;
+ break;
case ' ':
r->port_end = p;
/*
@@ -1287,6 +1300,10 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)
r->uri_ext = NULL;
r->args_start = NULL;
+ if (r->empty_path_in_uri) {
+ *u++ = '/';
+ }
+
ch = *p++;
while (p <= r->uri_end) {