hackney
hackney copied to clipboard
With follow_redirects, location/1 doesn't return correct redirected url
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.