benoitc / hackney

simple HTTP client in Erlang
Other
1.34k stars 427 forks source link

hackney erroring out when URL is "http://" #685

Closed albiere closed 3 years ago

albiere commented 3 years ago

Hey,

I'm working on an Elixir project that uses HTTPoison, which uses hackney under the hood, and noticed that when one passes the "https?://", hackney throws an error. I think hackney could return something similar to what it does when " " is passed in. The same error occur when a empty string is passed in.

iex(2)> :hackney.request(:get, " ")
{:error, :checkout_failure}
iex(3)> :hackney.request(:get, "https://asd")
{:error, :nxdomain}
iex(4)> :hackney.request(:get, "https://")
** (CaseClauseError) no case clause matching: []
    (hackney 1.17.0) /Users/angeloalbiero/Code/open_source/httpoison/deps/hackney/src/hackney_url.erl:248: :hackney_url.parse_netloc/2
    (hackney 1.17.0) /Users/angeloalbiero/Code/open_source/httpoison/deps/hackney/src/hackney.erl:351: :hackney.request/5
iex(4)>

If anybody here thinks this is a problem as well, I'd be more than happy to help coming up with a PR. The only problem is I'm super new to Elixir and Erlang.

ccarvalho-eng commented 3 years ago

Fixed this by updating hackney (mix deps.update hackney)

benoitc commented 3 years ago

which version of certifi is installed?

On Sat 8 May 2021 at 00:51, Cristiano Carvalho @.***> wrote:

That is happening to me as well:

iex(22)> HTTPoison.get("https://google.com") {:error, %HTTPoison.Error{id: nil, reason: :checkout_failure}} iex(23)> HTTPoison.get("http://google.com") {:ok, %HTTPoison.Response{ body: "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n301 Moved\n

301 Moved

\nThe document has moved\n<A HREF=\"http://www.google.com/\">here.\r\n\r\n", headers: [ {"Location", "http://www.google.com/"}, {"Content-Type", "text/html; charset=UTF-8"}, {"Date", "Fri, 07 May 2021 22:48:56 GMT"}, {"Expires", "Sun, 06 Jun 2021 22:48:56 GMT"}, {"Cache-Control", "public, max-age=2592000"}, {"Server", "gws"}, {"Content-Length", "219"}, {"X-XSS-Protection", "0"}, {"X-Frame-Options", "SAMEORIGIN"} ], request: %HTTPoison.Request{ body: "", headers: [], method: :get, options: [], params: %{}, url: "http://google.com" }, request_url: "http://google.com", status_code: 301 }}

It was working for me a few days ago. Now I always get the checkout failure.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/benoitc/hackney/issues/685#issuecomment-834836500, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADRIRCSDRD22OMZETEWWLTMRVGBANCNFSM427UBQTA .

-- Sent from my Mobile

ccarvalho-eng commented 3 years ago

Hi, @benoitc

these are the versions i updated to solve the issue above:

"certifi": {:hex, :certifi, "2.5.3" ... => "certifi": {:hex, :certifi, "2.6.1" "hackney": {:hex, :hackney, "1.17.0 ..." => "hackney": {:hex, :hackney, "1.17.4"

benoitc commented 3 years ago

ok thank you for your answer!