4 messages in ru.sysoev.nginxRequests with full URIs
FromSent OnAttachments
James OakleySep 24, 2007 7:26 am.patch
Igor SysoevSep 24, 2007 12:43 pm 
James OakleySep 25, 2007 10:44 am 
Igor SysoevSep 26, 2007 4:29 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Requests with full URIsActions...
From:James Oakley (jfun@public.gmane.org)
Date:Sep 24, 2007 7:26:06 am
List:ru.sysoev.nginx
Attachments:

I've noticed that Nginx supports full URIs in requests, which is great, since I need to be able to respond to proxy requests.

I have noticed one problem, though. If I request a URI like so:

curl -x 127.0.0.1:80 http://www.google.com/

It works, and I get the correct response (I'm using empty_gif to test this)

If I leave the trailing slash, however, I get a 400 instead:

curl -x 127.0.0.1:80 http://www.google.com <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <hr><center>nginx/0.5.31</center> </body> </html>

I have attached a patch that appears to fix the problem, but I have only just started looking at the code and I have no idea whether this was the correct way to fix it.

-- James Oakley jfunk-WR+XdX2NAhvN+rMO2@public.gmane.org

Index: nginx-0.5.31/src/http/ngx_http_parse.c =================================================================== --- nginx-0.5.31.orig/src/http/ngx_http_parse.c 2007-09-24 10:45:34.000000000
-0300 +++ nginx-0.5.31/src/http/ngx_http_parse.c 2007-09-24 11:24:28.000000000 -0300 @@ -345,6 +345,13 @@ ngx_http_parse_request_line(ngx_http_req r->uri_start = p; state = sw_after_slash_in_uri; break; + case ' ': + r->host_end = p; + r->uri.len = 1; + r->uri.data = (u_char *) "/"; + r->uri_start = NULL; + state = sw_http_09; + break; default: r->host_end = p; return NGX_HTTP_PARSE_INVALID_REQUEST; Index: nginx-0.5.31/src/http/ngx_http_request.c =================================================================== --- nginx-0.5.31.orig/src/http/ngx_http_request.c 2007-06-04 17:40:03.000000000
-0300 +++ nginx-0.5.31/src/http/ngx_http_request.c 2007-09-24 11:04:36.000000000 -0300 @@ -643,16 +643,20 @@ ngx_http_process_request_line(ngx_event_ if (r->args_start) { r->uri.len = r->args_start - 1 - r->uri_start; } else { - r->uri.len = r->uri_end - r->uri_start; + if (r->uri_start) { + r->uri.len = r->uri_end - r->uri_start; + } }

if (r->complex_uri || r->quoted_uri) {

- r->uri.data = ngx_palloc(r->pool, r->uri.len + 1); - if (r->uri.data == NULL) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - return; + if (r->uri_start) { + r->uri.data = ngx_palloc(r->pool, r->uri.len + 1); + if (r->uri.data == NULL) { + ngx_http_close_request(r,
NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } }

rc = ngx_http_parse_complex_uri(r); @@ -665,7 +669,9 @@ ngx_http_process_request_line(ngx_event_ }

} else { - r->uri.data = r->uri_start; + if (r->uri_start) { + r->uri.data = r->uri_start; + } }