Skip to content

Commit

Permalink
Merge pull request #1266 from arempe93/fix-allow-header
Browse files Browse the repository at this point in the history
Fix Allow header including OPTIONS when do_not_route_options! set
  • Loading branch information
dblock committed Feb 2, 2016
2 parents e54b8b0 + 9ce7b0e commit 86e3cd1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [#1225](https://github.com/ruby-grape/grape/pull/1225): Fix `given` with nested params not returning correct declared params - [@JanStevens](https://github.com/JanStevens).
* [#1249](https://github.com/ruby-grape/grape/pull/1249): Don't fail even if invalid type value is passed to default validator - [@namusyaka](https://github.com/namusyaka).
* [#1263](https://github.com/ruby-grape/grape/pull/1263): Fix `route :any, '*path'` breaking generated `OPTIONS`, Method Not Allowed routes - [@arempe93](https://github.com/arempe93).
* [#1266](https://github.com/ruby-grape/grape/pull/1266): Fix `Allow` header including `OPTIONS` when `do_not_route_options!` is active - [@arempe93](https://github.com/arempe93).

0.14.0 (12/07/2015)
===================
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def add_head_not_allowed_methods_and_options_methods
allowed_methods |= [Grape::Http::Headers::HEAD] if allowed_methods.include?(Grape::Http::Headers::GET)
end

allow_header = ([Grape::Http::Headers::OPTIONS] | allowed_methods).join(', ')
allow_header = (self.class.namespace_inheritable(:do_not_route_options) ? allowed_methods : [Grape::Http::Headers::OPTIONS] | allowed_methods).join(', ')

unless self.class.namespace_inheritable(:do_not_route_options)
generate_options_method(path, allow_header) unless allowed_methods.include?(Grape::Http::Headers::OPTIONS)
Expand Down
9 changes: 8 additions & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,16 @@ def subject.enable_root_route!
'example'
end
end
it 'options does not exist' do

it 'does not create an OPTIONS route' do
options '/example'
expect(last_response.status).to eql 405
end

it 'does not include OPTIONS in Allow header' do
options '/example'
expect(last_response.status).to eql 405
expect(last_response.headers['Allow']).to eql 'GET, HEAD'
end
end

Expand Down

0 comments on commit 86e3cd1

Please sign in to comment.