Process dynamic headers before making actual request#606
Merged
jnunemaker merged 7 commits intojnunemaker:masterfrom Aug 27, 2018
Merged
Process dynamic headers before making actual request#606jnunemaker merged 7 commits intojnunemaker:masterfrom
jnunemaker merged 7 commits intojnunemaker:masterfrom
Conversation
Owner
|
Hey! Thanks for contribution. I'm definitely going to review this but low on time right now. Know that I appreciate it and will do my best. Feel free to bug me if I haven't responded in a week or two. |
TheSmartnik
reviewed
Aug 27, 2018
lib/httparty.rb
Outdated
| end | ||
|
|
||
| def process_dynamic_headers(headers) | ||
| headers = headers.map do |header, value| |
Collaborator
There was a problem hiding this comment.
What you want here is Enumerable#each_with_object. Resulting code will much cleaner than map + conversion to hash
Contributor
Author
There was a problem hiding this comment.
@TheSmartnik thanks for the suggestion, changed the code accordingly.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I had a requirement where I had to pass
Request-IDheader in all the http calls. So I tried usingHTTParty.headers()method to achieve this. But while testing I realized that once the value is set in headers usingHTTParty.headers(), it will remain as is.But I want different behaviour where the value is evaluated every time the call is fired.
One idea is to accept block as header value which can be evaluated when the request is fired. I have solved it in my project by adding a patch to httparty. I thought it would be useful to others as well.
Example of dynamic header:
Awaiting for suggestion and feedback.