From 6c3dbc9027672a43842c397edf8fc477ae46991a Mon Sep 17 00:00:00 2001 From: Maxim Chernyak Date: Sat, 18 Sep 2010 04:08:48 -0400 Subject: [PATCH] Fix header capitalization by explicitly upcasing first letter of every word, and avoiding capitalize. [#5636 state:resolved] --- actionpack/lib/action_controller/metal/head.rb | 2 +- actionpack/test/controller/render_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index a5c9910..0d68fd4 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -22,7 +22,7 @@ module ActionController location = options.delete(:location) options.each do |key, value| - headers[key.to_s.dasherize.split(/-/).map { |v| v.capitalize }.join("-")] = value.to_s + headers[key.to_s.dasherize.split(/-/).map { |v| v[0].chr.upcase + v[1, v.size] }.join("-")] = value.to_s end self.status = status diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index ab12c0b..42723c8 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -488,6 +488,10 @@ class TestController < ActionController::Base head :x_custom_header => "something" end + def head_with_www_authenticate_header + head 'WWW-Authenticate' => 'something' + end + def head_with_status_code_first head :forbidden, :x_custom_header => "something" end @@ -1139,6 +1143,13 @@ class RenderTest < ActionController::TestCase assert_response :ok end + def test_head_with_www_authenticate_header + get :head_with_www_authenticate_header + assert_blank @response.body + assert_equal "something", @response.headers["WWW-Authenticate"] + assert_response :ok + end + def test_head_with_symbolic_status get :head_with_symbolic_status, :status => "ok" assert_equal 200, @response.status -- 1.7.2