Skip to content
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

Merged
merged 2 commits into from
Apr 21, 2017

Conversation

yamamotok
Copy link
Contributor

@yamamotok yamamotok commented Apr 20, 2017

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.

Copy link
Owner

@ridiculous ridiculous left a 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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, should be "either"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry..

return request_headers if @options[:headers] == :all

headers_needed = Array(@options[:headers])
Hash[request_headers.sort].select do |key, value|
Copy link
Owner

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)?

Copy link
Contributor Author

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) }
Copy link
Owner

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 ...

Copy link
Contributor Author

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),
Copy link
Owner

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

Copy link
Contributor Author

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
@yamamotok
Copy link
Contributor Author

Thank you for the review! Now the fix is done.

@ekampp
Copy link

ekampp commented Apr 21, 2017

@yamamotok good job!

Copy link
Owner

@ridiculous ridiculous left a 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 ❤️

@ridiculous ridiculous merged commit ab49f3a into ridiculous:master Apr 21, 2017
@yamamotok
Copy link
Contributor Author

Thank you all!

@ridiculous
Copy link
Owner

ridiculous commented Apr 22, 2017

Released in 1.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants