From 40fcf09b1c2fdd87be199bc7b68a28ae538fae3f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Sep 2009 19:31:30 -0700 Subject: http: support for simple HTTP/0.9 GET requests HTTP/0.9 only supports GET requests and didn't require a version number in the request line. Additionally, only a single CRLF was required. Note: we don't correctly generate HTTP/0.9 responses, yet. --- ext/unicorn_http/unicorn_http_common.rl | 6 ++++-- test/unit/test_http_parser_ng.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ext/unicorn_http/unicorn_http_common.rl b/ext/unicorn_http/unicorn_http_common.rl index bb2a3ef..5d46087 100644 --- a/ext/unicorn_http/unicorn_http_common.rl +++ b/ext/unicorn_http/unicorn_http_common.rl @@ -41,6 +41,7 @@ Request_URI = ((absolute_path | "*") >mark %request_uri) | Absolute_URI; Fragment = ( uchar | reserved )* >mark %fragment; Method = (token){1,20} >mark %request_method; + GetOnly = "GET" >mark %request_method; http_number = ( digit+ "." digit+ ) ; HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ; @@ -65,8 +66,9 @@ ChunkedBody := chunk* last_chunk @end_chunked_body; Trailers := (message_header)* CRLF @end_trailers; - Request = Request_Line (message_header)* CRLF @header_done; + FullRequest = Request_Line (message_header)* CRLF @header_done; + SimpleRequest = GetOnly " " Request_URI ("#"Fragment){0,1} CRLF @header_done; -main := Request; +main := FullRequest | SimpleRequest; }%% diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb index bacf2cf..d9ee9d2 100644 --- a/test/unit/test_http_parser_ng.rb +++ b/test/unit/test_http_parser_ng.rb @@ -281,4 +281,23 @@ class HttpParserNgTest < Test::Unit::TestCase assert ! @parser.keepalive? end + def test_parse_simple_request + parser = HttpParser.new + req = {} + http = "GET /read-rfc1945-if-you-dont-believe-me\r\n" + assert_equal req, parser.headers(req, http) + assert_equal '', http + expect = { + "SERVER_NAME"=>"localhost", + "rack.url_scheme"=>"http", + "REQUEST_PATH"=>"/read-rfc1945-if-you-dont-believe-me", + "PATH_INFO"=>"/read-rfc1945-if-you-dont-believe-me", + "REQUEST_URI"=>"/read-rfc1945-if-you-dont-believe-me", + "SERVER_PORT"=>"80", + "REQUEST_METHOD"=>"GET", + "QUERY_STRING"=>"" + } + assert_equal expect, req + end + end -- cgit v1.2.3-24-ge0c7