Skip to content

Commit 86e3cd1

Browse files
committed
Merge pull request #1266 from arempe93/fix-allow-header
Fix Allow header including OPTIONS when do_not_route_options! set
2 parents e54b8b0 + 9ce7b0e commit 86e3cd1

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [#1225](https://github.com/ruby-grape/grape/pull/1225): Fix `given` with nested params not returning correct declared params - [@JanStevens](https://github.com/JanStevens).
2020
* [#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).
2121
* [#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).
22+
* [#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).
2223

2324
0.14.0 (12/07/2015)
2425
===================

lib/grape/api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def add_head_not_allowed_methods_and_options_methods
165165
allowed_methods |= [Grape::Http::Headers::HEAD] if allowed_methods.include?(Grape::Http::Headers::GET)
166166
end
167167

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

170170
unless self.class.namespace_inheritable(:do_not_route_options)
171171
generate_options_method(path, allow_header) unless allowed_methods.include?(Grape::Http::Headers::OPTIONS)

spec/grape/api_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,16 @@ def subject.enable_root_route!
673673
'example'
674674
end
675675
end
676-
it 'options does not exist' do
676+
677+
it 'does not create an OPTIONS route' do
678+
options '/example'
679+
expect(last_response.status).to eql 405
680+
end
681+
682+
it 'does not include OPTIONS in Allow header' do
677683
options '/example'
678684
expect(last_response.status).to eql 405
685+
expect(last_response.headers['Allow']).to eql 'GET, HEAD'
679686
end
680687
end
681688

0 commit comments

Comments
 (0)