Skip to content

Commit 2fe0688

Browse files
author
Jonathan Garay
committed
* Fix: Formatter can parse symbol keys in the headers hash
* Added: Formatter hash test
1 parent e31fa39 commit 2fe0688

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/grape/middleware/formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def default_options
1515
end
1616

1717
def headers
18-
env.dup.inject({}){|h,(k,v)| h[k.downcase[5..-1]] = v if k.downcase.to_s.start_with?('http_'); h}
18+
env.dup.inject({}){|h,(k,v)| h[k.to_s.downcase[5..-1]] = v if k.downcase.to_s.start_with?('http_'); h}
1919
end
2020

2121
def before

spec/grape/middleware/formatter_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ def to_xml
116116
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/vnd.test-v1+xml'})
117117
subject.env['api.format'].should == :xml
118118
end
119+
120+
it 'should properly parse headers with symbols as hash keys' do
121+
subject.call({'PATH_INFO' => '/info', 'http_accept' => 'application/xml', :system_time => '091293'})
122+
subject.env[:system_time].should == '091293'
123+
end
119124
end
120125

121126
context 'Content-type' do

0 commit comments

Comments
 (0)