lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.74k stars 976 forks source link

URL not included in response hash #1474

Closed aaronstillwell closed 1 year ago

aaronstillwell commented 1 year ago

Basic Info

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

https://github.com/lostisland/faraday/blob/0e16de8e5ad3d29810c3388ea95836e0e4689635/lib/faraday/response.rb#L61-L66

iMacTia commented 1 year ago

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 commented 1 year ago

Fixed in #1475 🎉