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

Use cow_http2:parse_sequence/1

This commit is contained in:
Loïc Hoguin 2018-10-26 18:51:32 +02:00
parent e1d970b5eb
commit 7d118b547f
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -215,27 +215,15 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport,
%% HTTP/2 protocol parsing.
parse(State=#state{socket=Socket, transport=Transport, preface={sequence, TRef}}, Data) ->
case Data of
<< "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", Rest/bits >> ->
parse(State=#state{preface={sequence, TRef}}, Data) ->
case cow_http2:parse_sequence(Data) of
{ok, Rest} ->
parse(State#state{preface={settings, TRef}}, Rest);
_ when byte_size(Data) >= 24 ->
Transport:close(Socket),
exit({shutdown, {connection_error, protocol_error,
'The connection preface was invalid. (RFC7540 3.5)'}});
_ ->
Len = byte_size(Data),
<< Preface:Len/binary, _/bits >> = <<"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n">>,
case Data of
Preface ->
more ->
before_loop(State, Data);
_ ->
Transport:close(Socket),
exit({shutdown, {connection_error, protocol_error,
'The connection preface was invalid. (RFC7540 3.5)'}})
end
Error = {connection_error, _, _} ->
terminate(State, Error)
end;
%% @todo Perhaps instead of just more we can have {more, Len} to avoid all the checks.
parse(State=#state{http2_machine=HTTP2Machine}, Data) ->
MaxFrameSize = cow_http2_machine:get_local_setting(max_frame_size, HTTP2Machine),
case cow_http2:parse(Data, MaxFrameSize) of