Closed fchabouis closed 1 year ago
Opened a PR on the Hackney side https://github.com/benoitc/hackney/pull/692
Thanks, @AntoineAugusti !
Pending a release on Hackney side https://github.com/benoitc/hackney/pull/692#issuecomment-1468124743
(useful url for testing: https://httpbin.org/status/308)
Still not released (https://github.com/benoitc/hackney/compare/1.18.1...master), available in current master.
Hackney released new versions recently, would it be possible to bump it?
This should be fixed in https://github.com/edgurgel/httpoison/commit/5920e195437237f72673b0514656cedfea0b0603, would be nice to have a new release.
Hey team, HTTPoison declares hackney requirement as: [hackney](https://hex.pm/packages/hackney) ~> 1.17
so one can update hackney by doing mix deps.update hackney
and that's it. No need to update HTTPoison unless hackney 2.0.0 comes out.
Tried today with
and I get confusing results
iex> :hackney.request(:get, "https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/", [], "", [{:follow_redirect, false}])
{:ok, 308,
[
{"server", "nginx"},
{"date", "Wed, 15 Nov 2023 07:37:45 GMT"},
{"content-type", "text/html; charset=utf-8"},
{"content-length", "233"},
{"location", "/api/1/datasets/ametis/"},
{"access-control-allow-origin", "*"},
{"pragma", "public"},
{"cache-control", "public"},
{"x-content-type-options", "nosniff"},
{"x-xss-protection", "1; mode=block"},
{"x-frame-options", "SAMEORIGIN"}
], #Reference<0.2597323666.388235265.31870>}
iex> :hackney.request(:get, "https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/", [], "", [{:follow_redirect, true}])
{:ok, 200,
[
{"server", "nginx"},
{"date", "Wed, 15 Nov 2023 07:37:49 GMT"},
{"content-type", "application/json"},
{"content-length", "8873"},
{"vary", "Accept-Encoding"},
{"access-control-allow-origin", "*"},
{"pragma", "public"},
{"cache-control", "public"},
{"x-content-type-options", "nosniff"},
{"x-xss-protection", "1; mode=block"},
{"x-frame-options", "SAMEORIGIN"}
], #Reference<0.2597323666.387973123.235497>}
iex> HTTPoison.get!("https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/", follow_redirect: true)
%HTTPoison.Response{
status_code: 308,
body: "<!doctype html>\n<html lang=en>\n<title>Redirecting...</title>\n<h1>Redirecting...</h1>\n<p>You should be redirected automatically to the target URL: <a href=\"/api/1/datasets/ametis/\">/api/1/datasets/ametis/</a>. If not, click the link.\n",
headers: [
{"server", "nginx"},
{"date", "Wed, 15 Nov 2023 07:30:39 GMT"},
{"content-type", "text/html; charset=utf-8"},
{"content-length", "233"},
{"location", "/api/1/datasets/ametis/"},
{"access-control-allow-origin", "*"},
{"pragma", "public"},
{"cache-control", "public"},
{"x-content-type-options", "nosniff"},
{"x-xss-protection", "1; mode=block"},
{"x-frame-options", "SAMEORIGIN"}
],
request_url: "https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/",
request: %HTTPoison.Request{
method: :get,
url: "https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/",
headers: [follow_redirect: true],
body: "",
params: %{},
options: []
}
}
HTTPoison.get!("https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/", follow_redirect: true)
The options (follow_redirect: true
) must be the last argument. The second argument is the list of headers.
HTTPoison.get!("https://www.data.gouv.fr/api/1/datasets/fichier-gtfs/", [], follow_redirect: true)
Oh, my bad @edgurgel 🙈😬
Can confirm it works fine, thanks!
Hi, I understand from the documentation that performing a get request on an URL responding with a 308 code should yield a HTTPoison.MaybeRedirect, allowing me to perform a redirect by hand easily.
https://hexdocs.pm/httpoison/HTTPoison.MaybeRedirect.html#t:t/0
But I get a classical
%HTTPoison.Response
instead.For example :
Am I misunderstanding the documentation ?
(Ideally, I'd like 308 response to be automatically followed, but it seems to come from the underlying hackney lib https://github.com/benoitc/hackney/issues/635)
Thanks !