From 92edad53d2546f64fc6dc58b697487e2f7be8ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 10 Mar 2016 23:30:49 +0100 Subject: 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. --- src/cowboy_http.erl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/cowboy_http.erl') 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= -- cgit v1.2.3