mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
make cowboy_client:request() allow to override Host header
this will be used by tests
This commit is contained in:
parent
43b3c39a0c
commit
201c53cb9f
1 changed files with 10 additions and 7 deletions
|
@ -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).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue