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

URL not included in response hash #1474

Closed
aaronstillwell opened this issue Dec 26, 2022 · 2 comments
Closed

URL not included in response hash #1474

aaronstillwell opened this issue Dec 26, 2022 · 2 comments

Comments

@aaronstillwell
Copy link
Contributor

Basic Info

  • Faraday Version: 2.6.0 (though issue is present in latest afaik)
  • Ruby Version: 3.1.2

Issue description

The URL isn't available on the response object after being converted to a hash. When using certain middleware (e.g https://github.com/tisba/faraday-follow-redirects) the URL on the response isn't necessarily the same as on the request. This information can be therefore valuable to have to check the final URL used to fetch the response.

Steps to reproduce

res = Faraday.get 'https://httpbin.org/status/200'
puts res.env.url
# => #<URI::HTTPS https://httpbin.org/status/200>

dumped = Marshal::dump(res)
loaded = Marshal::load(dumped)

puts loaded.env.url
# => nil

Remediation

Assuming there are no unintended consequences of adding the url to the to_hash object, this should be an easy modification to make. (I am happy to follow up with a PR after discussion here).

def to_hash
{
status: env.status, body: env.body,
response_headers: env.response_headers
}
end

@iMacTia
Copy link
Member

iMacTia commented Dec 26, 2022

This looks like a safe change and it makes sense in the context mentioned in the issue.

I'd be happy to review a PR with sufficient test coverage 👍

@iMacTia
Copy link
Member

iMacTia commented Jan 16, 2023

Fixed in #1475 🎉

@iMacTia iMacTia closed this as completed Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants