diff options
author | Loïc Hoguin <[email protected]> | 2018-10-26 18:51:32 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-10-26 18:51:49 +0200 |
commit | 7d118b547fa8b979148b05d0c32baf65aebfab35 (patch) | |
tree | 689b2a4f43f6c8976766e1de4e0ef59493a89d14 /src | |
parent | e1d970b5eb02dbd68c249ae1c7bd8acaf6a938a9 (diff) | |
download | cowboy-7d118b547fa8b979148b05d0c32baf65aebfab35.tar.gz cowboy-7d118b547fa8b979148b05d0c32baf65aebfab35.tar.bz2 cowboy-7d118b547fa8b979148b05d0c32baf65aebfab35.zip |
Use cow_http2:parse_sequence/1
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http2.erl | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl index 5d5e308..86dcab7 100644 --- a/src/cowboy_http2.erl +++ b/src/cowboy_http2.erl @@ -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 -> - before_loop(State, Data); - _ -> - Transport:close(Socket), - exit({shutdown, {connection_error, protocol_error, - 'The connection preface was invalid. (RFC7540 3.5)'}}) - end + more -> + before_loop(State, Data); + 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 |