Skip to content

Commit 583c4e2

Browse files
committed
Merged from master.
2 parents 309321c + 6cf671f commit 583c4e2

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

README.markdown

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ versioning.
1515
* [Grape Google Group](http://groups.google.com/group/ruby-grape)
1616
* [Grape Wiki](https://github.com/intridea/grape/wiki)
1717

18+
## Project Tracking
19+
20+
* [Grape Google Group](http://groups.google.com/group/ruby-grape)
21+
* [Grape Wiki](https://github.com/intridea/grape/wiki)
22+
1823
## Installation
1924

2025
Grape is available as a gem, to install it just install the gem:
@@ -112,8 +117,7 @@ supplied. This behavior is similar to routing in Rails. To circumvent this defau
112117
one could use the `:strict` option. When this option is set to `true`, a `404 Not found` error
113118
is returned when no correct Accept header is supplied.
114119

115-
Serialization takes place automatically. For more detailed usage information,
116-
please visit the [Grape Wiki](http://github.com/intridea/grape/wiki).
120+
Serialization takes place automatically.
117121

118122
## Helpers
119123

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] = v; h}
18+
env.dup.inject({}){|h,(k,v)| h[k.downcase[5..-1]] = v if k.downcase.start_with?('http_'); h}
1919
end
2020

2121
def before

spec/grape/middleware/formatter_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,29 @@ def to_xml
8181

8282
context 'Accept header detection' do
8383
it 'should detect from the Accept header' do
84-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/xml'})
84+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/xml'})
8585
subject.env['api.format'].should == :xml
8686
end
8787

8888
it 'should look for case-indifferent headers' do
89-
subject.call({'PATH_INFO' => '/info', 'accept' => 'application/xml'})
89+
subject.call({'PATH_INFO' => '/info', 'http_accept' => 'application/xml'})
9090
subject.env['api.format'].should == :xml
9191
end
9292

9393
it 'should use quality rankings to determine formats' do
94-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/json; q=0.3,application/xml; q=1.0'})
94+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json; q=0.3,application/xml; q=1.0'})
9595
subject.env['api.format'].should == :xml
96-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/json; q=1.0,application/xml; q=0.3'})
96+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json; q=1.0,application/xml; q=0.3'})
9797
subject.env['api.format'].should == :json
9898
end
9999

100100
it 'should handle quality rankings mixed with nothing' do
101-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/json,application/xml; q=1.0'})
101+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json,application/xml; q=1.0'})
102102
subject.env['api.format'].should == :xml
103103
end
104104

105105
it 'should properly parse headers with other attributes' do
106-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/json; abc=2.3; q=1.0,application/xml; q=0.7'})
106+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json; abc=2.3; q=1.0,application/xml; q=0.7'})
107107
subject.env['api.format'].should == :json
108108
end
109109
end
@@ -149,16 +149,16 @@ def to_xml
149149

150150
context 'Input' do
151151
it 'should parse the body from a POST/PUT and put the contents into rack.request.form_hash' do
152-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/json', 'rack.input' => StringIO.new('{"is_boolean":true,"string":"thing"}')})
152+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json', 'rack.input' => StringIO.new('{"is_boolean":true,"string":"thing"}')})
153153
subject.env['rack.request.form_hash']['is_boolean'].should be_true
154154
subject.env['rack.request.form_hash']['string'].should == 'thing'
155155
end
156156
it 'should parse the body from an xml POST/PUT and put the contents into rack.request.from_hash' do
157-
subject.call({'PATH_INFO' => '/info.xml', 'Accept' => 'application/xml', 'rack.input' => StringIO.new('<thing><name>Test</name></thing>')})
157+
subject.call({'PATH_INFO' => '/info.xml', 'HTTP_ACCEPT' => 'application/xml', 'rack.input' => StringIO.new('<thing><name>Test</name></thing>')})
158158
subject.env['rack.request.form_hash']['thing']['name'].should == 'Test'
159159
end
160160
it 'should be able to fail gracefully if the body is regular POST content' do
161-
subject.call({'PATH_INFO' => '/info', 'Accept' => 'application/json', 'rack.input' => StringIO.new('name=Other+Test+Thing')})
161+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json', 'rack.input' => StringIO.new('name=Other+Test+Thing')})
162162
subject.env['rack.request.form_hash'].should be_nil
163163
end
164164
end

0 commit comments

Comments
 (0)