-
Notifications
You must be signed in to change notification settings - Fork 341
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
When following redirects, I'd like to be able to access the final location #90
Comments
From IRC, |
That's a great addition to the library. I think we got 2 options:
Thoughts, ideas? |
Your first option is in line with what I had in mind, but I think an You already support passing options to Hackney directly, to handle cases I'm happy to look into implementing either of these approaches if you have On Sat, Nov 7, 2015, 21:49 Eduardo Gurgel [email protected] wrote:
|
Yeah the former option seems good short-term but the latter seems better long-term as we won't stop people from using other hackney features. I would be happy to accept a PR with this change! :) Thank you very much 👍 |
Awesome! I should have some free time to work on this later this week. Thanks for the guidance. |
@edgurgel In the cases where no client is returned do we want to default to the EDIT: Having spoken to @benoitc in IRC, I believe the only cases where a client will not be returned are when making a HEAD request, and when using the with_body option. These are cases where the request_path may still differ, so returning |
I am trying to access the body of the response after following a redirect, something like this:
However, body is empty. Is this related to the issue you are discussing here? Or is there already a way to access the body after a redirect occurs? |
Can you check the headers and see if there's a "location" to follow? I think there's still another redirect to follow as you got a 302 even after 5 redirects. Also which version of HTTPoison are you using? Just the latests ones accept these options without being part of |
Here are the versions of the dependencies in my project: Anyway, I was performing the get on my personal blog homepage, which indeed has a redirect to GitHub pages. However, it is not giving 302 consistently, and I have only gotten 200 tonight! I will try again tomorrow and share the headers here. I wonder if their CDN might create a bunch of redirects if a cache isn't hit right away. |
I wasn't able to hit the 302 as I did last night, even after setting the redirect limit to 1. I will keep trying but for now I think I see how this is supposed to work. I'm assuming that if I hit a 302, there will not be any response body. Instead, I should follow redirects until I get 200. |
+1 |
Here's a workaround:
|
Was this change reverted? Just ran a test, and I'm not getting the final URL of a redirect. I see there's a workaround, but I'm confused as to why one would be necessary if this change landed. Thanks. |
As it stands now, following a redirect only returns the final response, and there is no way to determine what URL that response maps to. For example, the following call hits
tinfoil-fake-site.com
, but follows a redirect, and ends up onhttps://tinfoilsecurity.com
Since the final response does not have a location header (As it shouldn't!), we have no way of determining what page we ended up on.
The Hackney documentation claims that the "Last Location is stored in the location property of the client state," but I don't believe we have access to this from
HTTPoison
.I'll let you know if I find a way of accessing this information. I'm also happy to contribute a fix upstream if you have any ideas on a possible solution!
The text was updated successfully, but these errors were encountered: