aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-03-10 23:30:49 +0100
committerLoïc Hoguin <[email protected]>2016-03-10 23:30:49 +0100
commit92edad53d2546f64fc6dc58b697487e2f7be8ba9 (patch)
tree662d74aa991039d7dffca74953e17e2a7ae53e35 /src/cowboy_http.erl
parente87438ffb1c63615f46dd7a7344b05918116ed1a (diff)
downloadcowboy-92edad53d2546f64fc6dc58b697487e2f7be8ba9.tar.gz
cowboy-92edad53d2546f64fc6dc58b697487e2f7be8ba9.tar.bz2
cowboy-92edad53d2546f64fc6dc58b697487e2f7be8ba9.zip
Add the beginning of the rfc7540 test suite
Currently only testing handshake. Tests that pass currently involve no request/response. ALPN and prior knowledge support have some edge cases left to fix. HTTP/1.1 Upgrade has not been implemented yet.
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r--src/cowboy_http.erl19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index f9ee5ac..d694cff 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -302,7 +302,7 @@ parse_request(<< $\s, _/bits >>, State, _) ->
''}); %% @todo
%% We limit the length of the Request-line to MaxLength to avoid endlessly
%% reading from the socket and eventually crashing.
-parse_request(Buffer, State=#state{opts=Opts}, EmptyLines) ->
+parse_request(Buffer, State=#state{opts=Opts, in_streamid=InStreamID}, EmptyLines) ->
MaxLength = maps:get(max_request_line_length, Opts, 8000),
MaxEmptyLines = maps:get(max_empty_lines, Opts, 5),
case match_eol(Buffer, 0) of
@@ -324,6 +324,10 @@ parse_request(Buffer, State=#state{opts=Opts}, EmptyLines) ->
parse_version(Rest, State, <<"OPTIONS">>, <<"*">>, <<>>);
% << "CONNECT ", Rest/bits >> ->
% parse_authority( %% @todo
+ %% Accept direct HTTP/2 only at the beginning of the connection.
+ << "PRI * HTTP/2.0\r\n", _/bits >> when InStreamID =:= 1 ->
+ %% @todo Might be worth throwing to get a clean stacktrace.
+ http2_upgrade(State, Buffer, undefined);
_ ->
parse_method(Buffer, State, <<>>,
maps:get(max_method_length, Opts, 32))
@@ -636,6 +640,19 @@ request(Buffer, State0=#state{ref=Ref, transport=Transport, in_streamid=StreamID
end,
{request, Req, State, Buffer}.
+%% HTTP/2 upgrade.
+
+http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Transport,
+ opts=Opts, handler=Handler}, Buffer, Settings) ->
+ case Transport:secure() of
+ false ->
+ _ = cancel_request_timeout(State),
+ cowboy_http2:init(Parent, Ref, Socket, Transport, Opts, Handler, Buffer, Settings);
+ true ->
+ error_terminate(400, State, {connection_error, protocol_error,
+ 'Clients that support HTTP/2 over TLS MUST use ALPN. (RFC7540 3.4)'})
+ end.
+
%% Request body parsing.
parse_body(Buffer, State=#state{in_streamid=StreamID, in_state=