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

With follow_redirects, location/1 doesn't return correct redirected url #430

Open
mfclarke opened this issue Aug 19, 2017 · 0 comments · May be fixed by #451
Open

With follow_redirects, location/1 doesn't return correct redirected url #430

mfclarke opened this issue Aug 19, 2017 · 0 comments · May be fixed by #451

Comments

@mfclarke
Copy link

mfclarke commented Aug 19, 2017

It seems location/1 returns the request host with the redirected path, rather than the full redirected URL.

I'm an Elixir guy, so this is in iex:

iex(1)> :hackney.get("http://bit.ly/2uLLCAk",[],<<>>,[{:pool, :example_pool},{:connect_timeout, 4000},{:recv_timeout, 6000}])
{:ok, 301,
 [{"Server", "nginx"}, {"Date", "Sat, 19 Aug 2017 06:24:08 GMT"},
  {"Content-Type", "text/html; charset=utf-8"}, {"Content-Length", "173"},
  {"Connection", "keep-alive"}, {"Cache-Control", "private, max-age=90"},
  {"Location",
   "http://www.factmag.com/2017/07/28/kendrick-lamar-rihanna-partners-crime-loyalty-video/"},
  {"Set-Cookie",
   "_bit=h7j6o8-68e2e7d09074b34204-00o; Domain=bit.ly; Expires=Thu, 15 Feb 2018 06:24:08 GMT"}],
 #Reference<0.1378007063.185597956.88535>}

iex(2)> {_, _, _, client} = :hackney.get("http://bit.ly/2uLLCAk",[],<<>>,[{:pool, :example_pool},{:connect_timeout, 4000},{:recv_timeout, 6000},{:follow_redirect, true}])
{:ok, 200,
 [{"Date", "Sat, 19 Aug 2017 06:24:48 GMT"},
  {"Content-Type", "text/html; charset=\"UTF-8\""},
  {"Transfer-Encoding", "chunked"}, {"Connection", "keep-alive"},
  {"Set-Cookie",
   "__cfduid=d306342952360dc63b5ea9ed368133dec1503123885; expires=Sun, 19-Aug-18 06:24:45 GMT; path=/; domain=.factmag.com; HttpOnly"},
  {"Set-Cookie", "PHPSESSID=1s9d6hctg62imub9e1rm7m0gq0; path=/"},
  {"Expires", "Thu, 19 Nov 1981 08:52:00 GMT"},
  {"Cache-Control", "no-store, no-cache, must-revalidate"},
  {"Pragma", "no-cache"}, {"Vary", "Accept-Encoding,Cookie"},
  {"Link", "<http://www.factmag.com/wp-json/>; rel=\"https://api.w.org/\""},
  {"Link", "<http://www.factmag.com/?p=394544>; rel=shortlink"},
  {"Server", "cloudflare-nginx"}, {"CF-RAY", "390b081bf0973e92-ZRH"}],
 #Reference<0.1378007063.185597956.88576>}

iex(3)> :hackney.location(client)
"http://bit.ly/2017/07/28/kendrick-lamar-rihanna-partners-crime-loyalty-video/"

It should be returning the location from the 301 headers ({"Location", "http://www.factmag.com/2017/07/28/kendrick-lamar-rihanna-partners-crime-loyalty-video/"}) but seems to be just appending the new path to the old bit.ly host.

@tnt-dev tnt-dev linked a pull request Oct 26, 2017 that will close this issue
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 a pull request may close this issue.

1 participant