aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-01-02 14:10:01 +0100
committerLoïc Hoguin <[email protected]>2019-01-02 14:10:01 +0100
commitca0db57a30c4978f0291ef7900962ed9b8de005d (patch)
tree46ba3e7a0fbefac7f13f906d24190a0f86d920f1 /src
parent228879bfc4eda8bac1919bab176c859c64ac54c2 (diff)
downloadgun-ca0db57a30c4978f0291ef7900962ed9b8de005d.tar.gz
gun-ca0db57a30c4978f0291ef7900962ed9b8de005d.tar.bz2
gun-ca0db57a30c4978f0291ef7900962ed9b8de005d.zip
Don't send the default port in the host header for HTTP/1.1
Diffstat (limited to 'src')
-rw-r--r--src/gun_http.erl26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index 5229a6d..29ba758 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -332,14 +332,9 @@ keepalive(State) ->
headers(State=#http_state{socket=Socket, transport=Transport, version=Version,
out=head}, StreamRef, ReplyTo, Method, Host, Port, Path, Headers) ->
- Host2 = case Host of
- {local, _SocketPath} -> <<>>;
- Tuple when is_tuple(Tuple) -> inet:ntoa(Tuple);
- _ -> Host
- end,
Headers2 = lists:keydelete(<<"transfer-encoding">>, 1, Headers),
Headers3 = case lists:keymember(<<"host">>, 1, Headers) of
- false -> [{<<"host">>, [Host2, $:, integer_to_binary(Port)]}|Headers2];
+ false -> [{<<"host">>, host_header(Transport, Host, Port)}|Headers2];
true -> Headers2
end,
%% We use Headers2 because this is the smallest list.
@@ -356,15 +351,10 @@ headers(State=#http_state{socket=Socket, transport=Transport, version=Version,
request(State=#http_state{socket=Socket, transport=Transport, version=Version,
out=head}, StreamRef, ReplyTo, Method, Host, Port, Path, Headers, Body) ->
- Host2 = case Host of
- {local, _SocketPath} -> <<>>;
- Tuple when is_tuple(Tuple) -> inet:ntoa(Tuple);
- _ -> Host
- end,
Headers2 = lists:keydelete(<<"content-length">>, 1,
lists:keydelete(<<"transfer-encoding">>, 1, Headers)),
Headers3 = case lists:keymember(<<"host">>, 1, Headers) of
- false -> [{<<"host">>, [Host2, $:, integer_to_binary(Port)]}|Headers2];
+ false -> [{<<"host">>, host_header(Transport, Host, Port)}|Headers2];
true -> Headers2
end,
Headers4 = transform_header_names(State, Headers3),
@@ -377,6 +367,18 @@ request(State=#http_state{socket=Socket, transport=Transport, version=Version,
Body]),
new_stream(State#http_state{connection=Conn}, StreamRef, ReplyTo, Method).
+host_header(Transport, Host0, Port) ->
+ Host = case Host0 of
+ {local, _SocketPath} -> <<>>;
+ Tuple when is_tuple(Tuple) -> inet:ntoa(Tuple);
+ _ -> Host0
+ end,
+ case {Transport:name(), Port} of
+ {tcp, 80} -> Host;
+ {tls, 443} -> Host;
+ _ -> [Host, $:, integer_to_binary(Port)]
+ end.
+
transform_header_names(#http_state{transform_header_name = Fun}, Headers) ->
lists:keymap(Fun, 1, Headers).