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

Do not overwrite default headers unless specified #518

Conversation

CJStadler
Copy link

Previously, calling HTTParty.headers without an argument set
HTTParty.default_options[:headers] to an empty hash. Now the
default headers will only be set to an empty hash when one is
explicitly provided, otherwise they will remain nil.

The previous behavior was problematic because the default headers
for a request could either be nil or {}, depending on whether
HTTParty.headers had been called. When they are nil the
default headers from Net::HTTP are used.

@jnunemaker any feedback is appreciated! This feels to me like a bit more of a workaround than a real solution, but I don't see a cleaner solution without a somewhat larger refactor.

Thanks to @tomatoturnip for the original PR.

Previously, calling `HTTParty.headers` just to access them set
`HTTParty.default_options[:headers]` to an empty hash. Now they will
only be set to an empty hash when one is explicitly provided, otherwise
they will remain `nil`.

The previous behavior was problematic because the default headers
for a request could either be `nil` or `{}`, depending on whether
`HTTParty.headers` had been called. When they are `nil` the
default headers from Net::HTTP are used.
@CJStadler
Copy link
Author

Thanks @jnunemaker! 🤘

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.

2 participants