aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <[email protected]>2013-08-25 02:11:49 +0900
committerYAMAMOTO Takashi <[email protected]>2013-09-03 02:09:10 +0900
commit201c53cb9f8217d497fb7acae2fa7d64f04f4022 (patch)
treec6a5c9111fe3d5950778fb531c18c10f95fdba77
parent43b3c39a0c74f8dc98ad410d170a87ea5d5f1018 (diff)
downloadcowboy-201c53cb9f8217d497fb7acae2fa7d64f04f4022.tar.gz
cowboy-201c53cb9f8217d497fb7acae2fa7d64f04f4022.tar.bz2
cowboy-201c53cb9f8217d497fb7acae2fa7d64f04f4022.zip
make cowboy_client:request() allow to override Host header
this will be used by tests
-rw-r--r--src/cowboy_client.erl17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/cowboy_client.erl b/src/cowboy_client.erl
index b5f96b3..10aaa9c 100644
--- a/src/cowboy_client.erl
+++ b/src/cowboy_client.erl
@@ -93,16 +93,19 @@ request(Method, URL, Headers, Body, Client=#client{
end,
VersionBin = atom_to_binary(Version, latin1),
%% @todo do keepalive too, allow override...
- Headers2 = [
- {<<"host">>, FullHost},
+ Headers2 = case lists:keyfind(<<"host">>, 1, Headers) of
+ false -> [{<<"host">>, FullHost}|Headers];
+ _ -> Headers
+ end,
+ Headers3 = [
{<<"user-agent">>, <<"Cow">>}
- |Headers],
- Headers3 = case iolist_size(Body) of
- 0 -> Headers2;
- Length -> [{<<"content-length">>, integer_to_list(Length)}|Headers2]
+ |Headers2],
+ Headers4 = case iolist_size(Body) of
+ 0 -> Headers3;
+ Length -> [{<<"content-length">>, integer_to_list(Length)}|Headers3]
end,
HeadersData = [[Name, <<": ">>, Value, <<"\r\n">>]
- || {Name, Value} <- Headers3],
+ || {Name, Value} <- Headers4],
Data = [Method, <<" ">>, Path, <<" ">>, VersionBin, <<"\r\n">>,
HeadersData, <<"\r\n">>, Body],
raw_request(Data, Client2).