-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'headers' option to log request headers #17
Add 'headers' option to log request headers #17
Conversation
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.
Looks really good!
README.md
Outdated
@@ -53,13 +53,17 @@ The middleware logger can be customized with the following options: | |||
|
|||
* The `:logger` option can be any object that responds to `.info(String)` | |||
* The `:filter` option can be any object that responds to `.filter(Hash)` and returns a hash. | |||
* The `:headers` option can be eather `:all` or array of strings. |
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.
typo, should be "either"
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.
Sorry..
lib/grape/middleware/logger.rb
Outdated
return request_headers if @options[:headers] == :all | ||
|
||
headers_needed = Array(@options[:headers]) | ||
Hash[request_headers.sort].select do |key, value| |
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.
Instead of iterating over all headers, what about just iterating over the headers_needed
(which will likely be less)?
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.
Exactly. I will optimize this.
|
||
describe '#headers if no request header' do | ||
let(:env) { build :expected_env } | ||
before { subject.instance_variable_set(:@env, env) } |
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.
Some funky formatting going on here ...
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.
Sorry for the carelessness... A tab character is there.
|
||
context ':all option is set to option headers' do | ||
let(:options) { { | ||
filter: build(:param_filter), |
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.
These :options
should only be indented 2 spaces, please
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.
Yes.
- Fix typo in README - Replace tab character with spaces and correct wrong indents. - Bugfix: headers are not sorted by keys when the option is `:all` - Optimize filtering logic
Thank you for the review! Now the fix is done. |
@yamamotok good job! |
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.
Looks great! Thanks for the contribution ❤️
Thank you all! |
Released in 1.8.0 |
Enable to log request headers by
headers
option.Filtering is configurable, you can set
:all
to get all headers, or set%w(cache-control version)
to get only those two headers.This pull request is based on ideas in #9 and implements same functions with some improvement.