From 2d5a6a8183c04ef6d5f48daf5419147545b98389 Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Fri, 14 Feb 2020 11:14:51 +0100 Subject: [PATCH] Moved join in call_with_allow_headers. Instead of being joined by default it's joined when called Replaced 'OPTIONS' by actual Grape::Http::Headers::OPTIONS. --- CHANGELOG.md | 2 +- lib/grape/api/instance.rb | 2 +- lib/grape/router.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3f538873c..20df5dc6a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/lib/grape/api/instance.rb b/lib/grape/api/instance.rb index 84e36d467e..6844c08d16 100644 --- a/lib/grape/api/instance.rb +++ b/lib/grape/api/instance.rb @@ -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 diff --git a/lib/grape/router.rb b/lib/grape/router.rb index b309088427..26f20662ad 100644 --- a/lib/grape/router.rb +++ b/lib/grape/router.rb @@ -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 @@ -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