diff options
author | Loïc Hoguin <[email protected]> | 2019-01-06 17:01:41 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-01-06 17:01:41 +0100 |
commit | ab4878838fafbd453b41d031c9224b2ee8d2d956 (patch) | |
tree | 432a9fa69523af7637c3eeab0435b625c70a2cbd /test | |
parent | eee5a59bc1763fc2e1c8c6e7155939dd04d930b7 (diff) | |
download | gun-ab4878838fafbd453b41d031c9224b2ee8d2d956.tar.gz gun-ab4878838fafbd453b41d031c9224b2ee8d2d956.tar.bz2 gun-ab4878838fafbd453b41d031c9224b2ee8d2d956.zip |
Lowercase header names automatically and accept more types
Header names can now be provided as binary, string or atom
and Gun no longer requires them to be in lowercase. The list
of headers can also be provided as a map as well.
Diffstat (limited to 'test')
-rw-r--r-- | test/gun_SUITE.erl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl index 957d2df..dd7b083 100644 --- a/test/gun_SUITE.erl +++ b/test/gun_SUITE.erl @@ -28,6 +28,19 @@ all() -> %% Tests. +atom_header_name(_) -> + doc("Header names 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, "/", [ + {'User-Agent', "Gun/atom-headers"} + ]), + Data = receive_from(OriginPid), + Lines = binary:split(Data, <<"\r\n">>, [global]), + [<<"user-agent: Gun/atom-headers">>] = [L || <<"user-agent: ", _/bits>> = L <- Lines], + gun:close(Pid). + atom_hostname(_) -> doc("Hostnames may be given as atom."), {ok, OriginPid, OriginPort} = init_origin(tcp, http), @@ -207,6 +220,32 @@ killed_streams_http(_) -> error(timeout) end. +list_header_name(_) -> + doc("Header names may be given as list."), + {ok, OriginPid, OriginPort} = init_origin(tcp, http), + {ok, Pid} = gun:open("localhost", OriginPort), + {ok, http} = gun:await_up(Pid), + _ = gun:get(Pid, "/", [ + {"User-Agent", "Gun/list-headers"} + ]), + Data = receive_from(OriginPid), + Lines = binary:split(Data, <<"\r\n">>, [global]), + [<<"user-agent: Gun/list-headers">>] = [L || <<"user-agent: ", _/bits>> = L <- Lines], + gun:close(Pid). + +map_headers(_) -> + doc("Header names may be given as a map."), + {ok, OriginPid, OriginPort} = init_origin(tcp, http), + {ok, Pid} = gun:open("localhost", OriginPort), + {ok, http} = gun:await_up(Pid), + _ = gun:get(Pid, "/", #{ + <<"USER-agent">> => "Gun/map-headers" + }), + Data = receive_from(OriginPid), + Lines = binary:split(Data, <<"\r\n">>, [global]), + [<<"user-agent: Gun/map-headers">>] = [L || <<"user-agent: ", _/bits>> = L <- Lines], + gun:close(Pid). + reply_to(_) -> doc("The reply_to option allows using a separate process for requests."), do_reply_to(http), @@ -396,3 +435,16 @@ do_unix_socket_connect() -> after 250 -> error(timeout) end. + +uppercase_header_name(_) -> + doc("Header names may be given with uppercase characters."), + {ok, OriginPid, OriginPort} = init_origin(tcp, http), + {ok, Pid} = gun:open("localhost", OriginPort), + {ok, http} = gun:await_up(Pid), + _ = gun:get(Pid, "/", [ + {<<"USER-agent">>, "Gun/uppercase-headers"} + ]), + Data = receive_from(OriginPid), + Lines = binary:split(Data, <<"\r\n">>, [global]), + [<<"user-agent: Gun/uppercase-headers">>] = [L || <<"user-agent: ", _/bits>> = L <- Lines], + gun:close(Pid). |