diff options
author | Loïc Hoguin <[email protected]> | 2019-01-05 22:50:45 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-01-05 22:50:45 +0100 |
commit | 36d44cbdd5d9df21b8ed4eac60a1fadd25a2ea25 (patch) | |
tree | bf3cda9f178b21fb030519ad2f62faed89174f2e | |
parent | 08c4a71c801246c66427f2a37d2f0f6de561d448 (diff) | |
download | gun-36d44cbdd5d9df21b8ed4eac60a1fadd25a2ea25.tar.gz gun-36d44cbdd5d9df21b8ed4eac60a1fadd25a2ea25.tar.bz2 gun-36d44cbdd5d9df21b8ed4eac60a1fadd25a2ea25.zip |
Fix atom hostnames
-rw-r--r-- | src/gun_http.erl | 1 | ||||
-rw-r--r-- | test/gun_SUITE.erl | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl index ec459a3..e6b597c 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -374,6 +374,7 @@ host_header(Transport, Host0, Port) -> Host = case Host0 of {local, _SocketPath} -> <<>>; Tuple when is_tuple(Tuple) -> inet:ntoa(Tuple); + Atom when is_atom(Atom) -> atom_to_list(Atom); _ -> Host0 end, case {Transport:name(), Port} of diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl index ba5b523..93a09cc 100644 --- a/test/gun_SUITE.erl +++ b/test/gun_SUITE.erl @@ -20,6 +20,7 @@ -import(ct_helper, [name/0]). -import(gun_test, [init_origin/2]). -import(gun_test, [init_origin/3]). +-import(gun_test, [receive_from/1]). -import(gun_test, [receive_all_from/2]). all() -> @@ -27,6 +28,17 @@ all() -> %% Tests. +atom_hostname(_) -> + doc("Hostnames may be given as atom."), + {ok, OriginPid, OriginPort} = init_origin(tcp, http), + {ok, Pid} = gun:open('localhost', OriginPort), + {ok, http} = gun:await_up(Pid), + _ = gun:get(Pid, "/"), + Data = receive_from(OriginPid), + Lines = binary:split(Data, <<"\r\n">>, [global]), + [<<"host: localhost:", _/bits>>] = [L || <<"host: ", _/bits>> = L <- Lines], + gun:close(Pid). + connect_timeout(_) -> doc("Ensure an integer value for connect_timeout is accepted."), {ok, Pid} = gun:open("localhost", 12345, #{connect_timeout => 1000, retry => 0}), |