aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_http2.erl7
-rw-r--r--src/cowboy_req.erl2
-rw-r--r--test/req_SUITE.erl6
3 files changed, 13 insertions, 2 deletions
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl
index dfda305..d40046e 100644
--- a/src/cowboy_http2.erl
+++ b/src/cowboy_http2.erl
@@ -1119,7 +1119,8 @@ stream_req_init(State=#state{ref=Ref, peer=Peer, sock=Sock, cert=Cert},
StreamID, IsFin, Headers, PseudoHeaders=#{method := Method, scheme := Scheme,
authority := Authority, path := PathWithQs}, BodyLength) ->
try cow_http_hd:parse_host(Authority) of
- {Host, Port} ->
+ {Host, Port0} ->
+ Port = ensure_port(Scheme, Port0),
try cow_http:parse_fullpath(PathWithQs) of
{<<>>, _} ->
stream_malformed(State, StreamID,
@@ -1160,6 +1161,10 @@ stream_req_init(State=#state{ref=Ref, peer=Peer, sock=Sock, cert=Cert},
'The :authority pseudo-header is invalid. (RFC7540 8.1.2.3)')
end.
+ensure_port(<<"http">>, undefined) -> 80;
+ensure_port(<<"https">>, undefined) -> 443;
+ensure_port(_, Port) -> Port.
+
stream_closed(State=#state{socket=Socket, transport=Transport}, StreamID, _) ->
Transport:send(Socket, cow_http2:rst_stream(StreamID, stream_closed)),
State.
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 7b5cc5b..d8fe70d 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -110,7 +110,7 @@
method => binary(),
scheme => binary(),
host => binary(),
- port => binary(),
+ port => inet:port_number(),
qs => binary()
}.
-export_type([push_opts/0]).
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index 50001b2..aa5387c 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -334,6 +334,12 @@ port(Config) ->
Port = integer_to_binary(config(port, Config)),
Port = do_get_body("/port", Config),
Port = do_get_body("/direct/port", Config),
+ ExpectedPort = case config(type, Config) of
+ tcp -> <<"80">>;
+ ssl -> <<"443">>
+ end,
+ ExpectedPort = do_get_body("/port", [{<<"host">>, <<"localhost">>}], Config),
+ ExpectedPort = do_get_body("/direct/port", [{<<"host">>, <<"localhost">>}], Config),
ok.
qs(Config) ->