Skip to content

Commit

Permalink
Moved join in call_with_allow_headers. Instead of being joined by def…
Browse files Browse the repository at this point in the history
…ault it's joined when called

Replaced 'OPTIONS' by actual Grape::Http::Headers::OPTIONS.
  • Loading branch information
ericproulx committed Feb 14, 2020
1 parent 3f17a27 commit 2d5a6a8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Your contribution here.

#### Fixes

* [#1993](/~https://github.com/ruby-grape/grape/pull/1993): Lazy join allow header - [@ericproulx](/~https://github.com/ericproulx).
* [#1987](/~https://github.com/ruby-grape/grape/pull/1987): Re-add exactly_one_of mutually exclusive error message - [@ZeroInputCtrl](/~https://github.com/ZeroInputCtrl).
* [#1977](/~https://github.com/ruby-grape/grape/pull/1977): Skip validation for a file if it is optional and nil - [@dnesteryuk](/~https://github.com/dnesteryuk).
* [#1976](/~https://github.com/ruby-grape/grape/pull/1976): Ensure classes/modules listed for autoload really exist - [@dnesteryuk](/~https://github.com/dnesteryuk).
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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 = (self.class.namespace_inheritable(:do_not_route_options) ? allowed_methods : [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)

unless self.class.namespace_inheritable(:do_not_route_options) || allowed_methods.include?(Grape::Http::Headers::OPTIONS)
config[:endpoint].options[:options_route_enabled] = true
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def transaction(env)
env,
neighbor.allow_header,
neighbor.endpoint
) if neighbor && method == 'OPTIONS' && !cascade
) if neighbor && method == Grape::Http::Headers::OPTIONS && !cascade

route = match?(input, '*')
return neighbor.endpoint.call(env) if neighbor && cascade && route
Expand Down Expand Up @@ -160,7 +160,7 @@ def greedy_match?(input)
end

def call_with_allow_headers(env, methods, endpoint)
env[Grape::Env::GRAPE_ALLOWED_METHODS] = methods
env[Grape::Env::GRAPE_ALLOWED_METHODS] = methods.join(', ')
endpoint.call(env)
end

Expand Down

0 comments on commit 2d5a6a8

Please sign in to comment.