From 066226e97c1a08f927f62ae50d7e95a9ada4f303 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 29 Mar 2009 19:01:24 -0700 Subject: http11: use :http_body instead of "HTTP_BODY" "HTTP_BODY" could conflict with a "Body:" HTTP header if there ever is one. Also, try to hide this body from the Rack environment before @app is called since it is only used by Unicorn internally. --- ext/unicorn/http11/http11.c | 6 +++--- lib/unicorn/const.rb | 3 --- lib/unicorn/http_request.rb | 2 +- test/unit/test_http_parser.rb | 4 ++-- test/unit/test_request.rb | 2 ++ 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/unicorn/http11/http11.c b/ext/unicorn/http11/http11.c index f62dce7..421e4d5 100644 --- a/ext/unicorn/http11/http11.c +++ b/ext/unicorn/http11/http11.c @@ -19,6 +19,7 @@ static VALUE mUnicorn; static VALUE cHttpParser; static VALUE eHttpParserError; +static VALUE sym_http_body; #define HTTP_PREFIX "HTTP_" #define HTTP_PREFIX_LEN (sizeof(HTTP_PREFIX) - 1) @@ -31,7 +32,6 @@ static VALUE global_http_version; static VALUE global_content_length; static VALUE global_request_path; static VALUE global_content_type; -static VALUE global_http_body; static VALUE global_server_name; static VALUE global_server_port; static VALUE global_server_protocol; @@ -299,7 +299,7 @@ static void header_done(void *data, const char *at, size_t length) } /* grab the initial body and stuff it into the hash */ - rb_hash_aset(req, global_http_body, rb_str_new(at, length)); + rb_hash_aset(req, sym_http_body, rb_str_new(at, length)); rb_hash_aset(req, global_server_protocol, global_server_protocol_value); } @@ -413,7 +413,6 @@ void Init_http11() DEF_GLOBAL(http_version, "HTTP_VERSION"); DEF_GLOBAL(request_path, "REQUEST_PATH"); DEF_GLOBAL(content_length, "CONTENT_LENGTH"); - DEF_GLOBAL(http_body, "HTTP_BODY"); DEF_GLOBAL(content_type, "CONTENT_TYPE"); DEF_GLOBAL(server_name, "SERVER_NAME"); DEF_GLOBAL(server_port, "SERVER_PORT"); @@ -430,5 +429,6 @@ void Init_http11() rb_define_method(cHttpParser, "initialize", HttpParser_init,0); rb_define_method(cHttpParser, "reset", HttpParser_reset,0); rb_define_method(cHttpParser, "execute", HttpParser_execute,2); + sym_http_body = ID2SYM(rb_intern("http_body")); init_common_fields(); } diff --git a/lib/unicorn/const.rb b/lib/unicorn/const.rb index f2143bf..3a3d143 100644 --- a/lib/unicorn/const.rb +++ b/lib/unicorn/const.rb @@ -54,9 +54,6 @@ module Unicorn # This is the part of the path after the SCRIPT_NAME. PATH_INFO="PATH_INFO".freeze - # Request body - HTTP_BODY="HTTP_BODY".freeze - # The original URI requested by the client. REQUEST_URI='REQUEST_URI'.freeze REQUEST_PATH='REQUEST_PATH'.freeze diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 70378ef..750deea 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -83,7 +83,7 @@ module Unicorn # Handles dealing with the rest of the request # returns a Rack environment if successful, raises an exception if not def handle_body(socket) - http_body = @params[Const::HTTP_BODY] + http_body = @params.delete(:http_body) content_length = @params[Const::CONTENT_LENGTH].to_i remain = content_length - http_body.length diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index 1deeaa2..57c8db2 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -113,7 +113,7 @@ class HttpParserTest < Test::Unit::TestCase assert_equal 'PUT', req['REQUEST_METHOD'] assert_equal 'HTTP/1.0', req['HTTP_VERSION'] assert_equal 'HTTP/1.1', req['SERVER_PROTOCOL'] - assert_equal "abcde", req['HTTP_BODY'] + assert_equal "abcde", req[:http_body] end def test_put_body_later @@ -126,7 +126,7 @@ class HttpParserTest < Test::Unit::TestCase assert_equal 'PUT', req['REQUEST_METHOD'] assert_equal 'HTTP/1.0', req['HTTP_VERSION'] assert_equal 'HTTP/1.1', req['SERVER_PROTOCOL'] - assert_equal "", req['HTTP_BODY'] + assert_equal "", req[:http_body] end def test_fragment_in_uri diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb index 37fbb14..7a4b92b 100644 --- a/test/unit/test_request.rb +++ b/test/unit/test_request.rb @@ -50,6 +50,7 @@ class RequestTest < Test::Unit::TestCase "abcde") res = env = nil assert_nothing_raised { env = @request.read(client) } + assert ! env.include?(:http_body) assert_nothing_raised { res = @lint.call(env) } end @@ -71,6 +72,7 @@ class RequestTest < Test::Unit::TestCase assert_equal 0, client.sysseek(0) res = env = nil assert_nothing_raised { env = @request.read(client) } + assert ! env.include?(:http_body) assert_equal length, env['rack.input'].size count.times { assert_equal buf, env['rack.input'].read(bs) } assert_nil env['rack.input'].read(bs) -- cgit v1.2.3-24-ge0c7