comparison src/http/ngx_http_request.c @ 7752:8989fbd2f89a

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 10 Dec 2020 20:09:30 +0300
parents 7efae6b4cfb0
children 2fec22332ff4
comparison
equal deleted inserted replaced
7751:7efae6b4cfb0 7752:8989fbd2f89a
1222 r->uri.len = r->args_start - 1 - r->uri_start; 1222 r->uri.len = r->args_start - 1 - r->uri_start;
1223 } else { 1223 } else {
1224 r->uri.len = r->uri_end - r->uri_start; 1224 r->uri.len = r->uri_end - r->uri_start;
1225 } 1225 }
1226 1226
1227 if (r->complex_uri || r->quoted_uri) { 1227 if (r->complex_uri || r->quoted_uri || r->empty_path_in_uri) {
1228
1229 if (r->empty_path_in_uri) {
1230 r->uri.len++;
1231 }
1228 1232
1229 r->uri.data = ngx_pnalloc(r->pool, r->uri.len + 1); 1233 r->uri.data = ngx_pnalloc(r->pool, r->uri.len + 1);
1230 if (r->uri.data == NULL) { 1234 if (r->uri.data == NULL) {
1231 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 1235 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1232 return NGX_ERROR; 1236 return NGX_ERROR;
1248 } 1252 }
1249 1253
1250 r->unparsed_uri.len = r->uri_end - r->uri_start; 1254 r->unparsed_uri.len = r->uri_end - r->uri_start;
1251 r->unparsed_uri.data = r->uri_start; 1255 r->unparsed_uri.data = r->uri_start;
1252 1256
1253 r->valid_unparsed_uri = r->space_in_uri ? 0 : 1; 1257 r->valid_unparsed_uri = (r->space_in_uri || r->empty_path_in_uri) ? 0 : 1;
1254 1258
1255 if (r->uri_ext) { 1259 if (r->uri_ext) {
1256 if (r->args_start) { 1260 if (r->args_start) {
1257 r->exten.len = r->args_start - 1 - r->uri_ext; 1261 r->exten.len = r->args_start - 1 - r->uri_ext;
1258 } else { 1262 } else {