From 41a14dcd1045f61278237f34f065b87212689376 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 13 Mar 2013 18:05:01 +0100 Subject: `Http::Headers` directly modifies the passed environment. The env hash passed to `Http::Headers#new` must be in env format. Also be aware that the passed hash is modified directly. docs and test-cases for setting headers/env in functional tests. Follow up to #9700. --- actionpack/test/dispatch/header_test.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'actionpack/test/dispatch/header_test.rb') diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 3bb3b3db23..9e37b96951 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -8,15 +8,15 @@ class HeaderTest < ActiveSupport::TestCase ) end - test "#new with mixed headers and env" do + test "#new does not normalize the data" do headers = ActionDispatch::Http::Headers.new( "Content-Type" => "application/json", "HTTP_REFERER" => "/some/page", "Host" => "http://test.com") - assert_equal({"CONTENT_TYPE" => "application/json", + assert_equal({"Content-Type" => "application/json", "HTTP_REFERER" => "/some/page", - "HTTP_HOST" => "http://test.com"}, headers.env) + "Host" => "http://test.com"}, headers.env) end test "#env returns the headers as env variables" do @@ -117,11 +117,21 @@ class HeaderTest < ActiveSupport::TestCase end test "symbols are treated as strings" do - headers = ActionDispatch::Http::Headers.new(:SERVER_NAME => "example.com", - "HTTP_REFERER" => "/", - :Host => "test.com") + headers = ActionDispatch::Http::Headers.new + headers.merge!(:SERVER_NAME => "example.com", + "HTTP_REFERER" => "/", + :Host => "test.com") assert_equal "example.com", headers["SERVER_NAME"] assert_equal "/", headers[:HTTP_REFERER] assert_equal "test.com", headers["HTTP_HOST"] end + + test "headers directly modifies the passed environment" do + env = {"HTTP_REFERER" => "/"} + headers = ActionDispatch::Http::Headers.new(env) + headers['Referer'] = "http://example.com/" + headers.merge! "CONTENT_TYPE" => "text/plain" + assert_equal({"HTTP_REFERER"=>"http://example.com/", + "CONTENT_TYPE"=>"text/plain"}, env) + end end -- cgit v1.2.3