edgurgel / httpoison

Yet Another HTTP client for Elixir powered by hackney
https://hex.pm/packages/httpoison
MIT License
2.23k stars 341 forks source link

ipv6 localhost address is passed to hackney without square brackets #475

Open philippseith opened 1 year ago

philippseith commented 1 year ago

I am trying to build a simple reverse proxy with https://hexdocs.pm/reverse_proxy_plug and its httpoison plugin. I am trying to forward requests to a (angular dev-). server, listening on localhost:4200. As localhost is ipv6 on macOS and hackney does not seem to resolve this correctly (see https://github.com/benoitc/hackney/issues/718), I set the upstream to "http://[::1]:4200/" which reaches :hackney.request/5 as "http://::1:4200" and causes

 1st argument: not a textual representation of an integer

        :erlang.list_to_integer(':1:4200')
        (hackney 1.18.1) /Users/philipp/wspc/elixir/rest_api/deps/hackney/src/hackney_url.erl:260: :hackney_url.parse_netloc/2
        (hackney 1.18.1) /Users/philipp/wspc/elixir/rest_api/deps/hackney/src/hackney.erl:351: :hackney.request/5

IMHO the square brackets must not be removed from the url.

used versions: OTP 25 Elixir 1.14.1 Httpoison 2.1.0 hackney 1.18.1

Chlorophytus commented 1 year ago

I got Elixir 1.14.5 set up with lighttpd hosting a single file bound on that [::1] IP address. It's also using Erlang/OTP 25.3.2.6.

iex> HTTPoison.get!("[::1]:8080/index.txt")
%HTTPoison.Response{
  status_code: 200,
  body: "Hello, Elixir!\n",
  headers: [
    {"Content-Type", "text/plain;charset=utf-8"},
    {"ETag", "\"4116816263\""},
    {"Last-Modified", "Fri, 06 Oct 2023 20:43:35 GMT"},
    {"Content-Length", "15"},
    {"Accept-Ranges", "bytes"},
    {"Date", "Fri, 06 Oct 2023 20:55:21 GMT"},
    {"Server", "lighttpd/1.4.71"}
  ],
  request_url: "http://[::1]:8080/index.txt",
  request: %HTTPoison.Request{
    method: :get,
    url: "http://[::1]:8080/index.txt",
    headers: [],
    body: "",
    params: %{},
    options: []
  }
}

I'm not sure how to reproduce the bug, did it get fixed on your end?