httpoison
httpoison copied to clipboard
Add the location to all responses returned
This closes #90
There's two things to note in this pull request:
-
We're forced to read the location off of the
client_ref()
before we read the body. In the current version of Hackney, reading the body destroys thatclient_ref()
. A new release of Hackney will be released within the next week or so that resolves this issue, at which point we can inline the call to:hackney.location(client)
-
In the cases where a
client_ref()
is not returned, I've chosen to returnnil
as the location. I would prefer always returning the location, but defaulting torequest_url
is not reliable. Both HEAD requests and requests that make use of thewith_body
parameter are still capable of following redirects, but will not return aclient_ref()
. Let me know if you'd prefer different behaviour here.
I'm happy to modify this pull request once we get the new version of Hackney. Once we have that, I'll also open a new PR to return the client_ref()
Thanks for the PR! I will check soon! :+1:
If we merge this we will include location to the struct and it will be harder to remove as we would need to deprecate etc etc. I'm not sure if it's better to wait for the next hackney version or keep it for now.
Any thoughts @ShaneWilton and @benoitc?
I think that having the client will be really useful to give proper tools for request and response streaming (https://github.com/edgurgel/httpoison/issues/97)
I'd agree with the deprecation point. I'm happy to wait for the next version of Hackney, then swap out the location for the client. Calling into Hackney directly isn't too bad.
What if we expose HTTPoison.Response.location/1
? Now it would simply return location
from the struct but we advise to use the function instead of direct access? Then with next hackney we would keep the API and instead of going for the location we would use the client to fetch the location.
What do you think?
Sorry about vanishing for a while, I got swamped with other work.
I just looked into this again, and as far as I can tell, the client_ref
changes were never committed to Hackney. I'll implement the changes you requested and update the PR!
which change to client_ref?
there is an update of hackney that will land sometimes this week which simplify the api. It will be easier to retrieve and reuse the location with it.
@benoitc Right now, reading the body off a client_ref
will destroy that client_ref
. This means that we need to first read the location, and return it as part of the struct.
Ideally, we'd like to return the client_ref
in the struct instead, to expose all of Hackney's API.
OK I see. It should be handled in the coming version then :) I will try to publish it before friday.
@benoitc That's great to hear, thanks!
@edgurgel I've updated the PR to wrap the location behind a method on Response. Feel free to hold off on this if you'd rather wait until we get the new Hackney though :)
Has Hackney added the update this is waiting on? I'd love to see this feature merged!
I also would like to know if there is any roadblock from getting this to merge.
Would still love to see this make the 1.0.0 release cycle!
It seams the location
prop was removed, how to get the last-location?
Any news on that ? I would love to see this feature too
Yeah, still no news on the subject? I would really need to have the location of the response as well.
@edgurgel is there anything I can help with to make this be included into HTTPoison?
@bitboxer yes! Would you mind setting up a new PR with the necessary changes? I'm keen to get this merged 👍
@edgurgel okay, will try do this tonight.
well why not using hackney:get_location? i'm confused.
@benoitc now you are confusing me :wink: . What do you mean by that?