0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

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.
This commit is contained in:
Loïc Hoguin 2016-03-10 23:30:49 +01:00
parent e87438ffb1
commit 92edad53d2
5 changed files with 740 additions and 25 deletions

View file

@ -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=