From 41e3dcf47d8ee855747681b80dab1c3b9d6bc457 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 2 Sep 2009 18:21:09 -0700 Subject: expose the $content_length/$content_type variables Since the HTTP_CONTENT_LENGTH and HTTP_CONTENT_TYPE variables are not allowed by Rack, we need to allow access to the CGI variables instead. --- README.txt | 4 ++++ lib/clogger.rb | 2 +- test/test_clogger.rb | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 63a180a..7f042ee 100644 --- a/README.txt +++ b/README.txt @@ -43,6 +43,10 @@ somewhere inside the "Rails::Initializer.run do |config|" block: * $http_* - HTTP request headers (e.g. $http_user_agent) * $sent_http_* - HTTP response headers (e.g. $sent_http_content_length) +* $content_length - HTTP request body size + ($http_content_length is not allowed by Rack) +* $content_type - HTTP request content type + ($http_content_type is not allowed by Rack) * $cookie_* - HTTP request cookie (e.g. $cookie_session_id) Rack::Request#cookies must have been used by the underlying application to parse the cookies into a hash. diff --git a/lib/clogger.rb b/lib/clogger.rb index 8538048..52f2723 100644 --- a/lib/clogger.rb +++ b/lib/clogger.rb @@ -35,7 +35,7 @@ class Clogger private CGI_ENV = Regexp.new('\A\$(' << - %w(request_method + %w(request_method content_length content_type remote_addr remote_ident remote_user path_info query_string script_name server_name server_port).join('|') << ')\z').freeze diff --git a/test/test_clogger.rb b/test/test_clogger.rb index 5b81125..4dc1371 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -410,4 +410,20 @@ class TestClogger < Test::Unit::TestCase assert_equal "GET\n", str.string end + def test_content_length_null + str = StringIO.new + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => str, :format => '$content_length') + cl.call(@req) + assert_equal "-\n", str.string + end + + def test_content_length_set + str = StringIO.new + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => str, :format => '$content_length') + cl.call(@req.merge('CONTENT_LENGTH' => '5')) + assert_equal "5\n", str.string + end + end -- cgit v1.2.3-24-ge0c7