-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from niedhui/master
extract headers and params from Endpoint to Grape::Request
- Loading branch information
Showing
4 changed files
with
26 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Grape | ||
class Request < Rack::Request | ||
|
||
def params | ||
@env['grape.request.params'] ||= Hashie::Mash.new. | ||
deep_merge(super). | ||
deep_merge(env['rack.routing_args'] || {}) | ||
end | ||
|
||
def headers | ||
@env['grape.request.headers'] ||= @env.dup.inject({}) { |h, (k, v)| | ||
if k.start_with? 'HTTP_' | ||
k = k[5..-1].gsub('_', '-').downcase.gsub(/^.|[-_\s]./) { |x| x.upcase } | ||
h[k] = v | ||
end | ||
h | ||
} | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d4a3cb3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great commit, however, the message does not indicate a change in behavior which has been introduced. The headers and params are now stored in the env. This is not a Bad Thing, but perhaps it warrants a message like 'Store headers and params in Rack env to (accommodate | repair | what?)...'
d4a3cb3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally, @niedhui, could you please update the CHANGELOG? Thx.