From a670e3bf723eae094f82520f38cad40c609b1cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 26 Oct 2018 18:50:10 +0200 Subject: Add cow_http2:parse_sequence/1 --- src/cow_http2.erl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cow_http2.erl b/src/cow_http2.erl index ec4aab9..225d2ec 100644 --- a/src/cow_http2.erl +++ b/src/cow_http2.erl @@ -15,6 +15,7 @@ -module(cow_http2). %% Parsing. +-export([parse_sequence/1]). -export([parse/1]). -export([parse/2]). -export([parse_settings_payload/1]). @@ -83,6 +84,24 @@ %% Parsing. +-spec parse_sequence(binary()) + -> {ok, binary()} | more | {connection_error, error(), atom()}. +parse_sequence(<<"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", Rest/bits>>) -> + {ok, Rest}; +parse_sequence(Data) when byte_size(Data) >= 24 -> + {connection_error, protocol_error, + 'The connection preface was invalid. (RFC7540 3.5)'}; +parse_sequence(Data) -> + Len = byte_size(Data), + <> = <<"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n">>, + case Data of + Preface -> + more; + _ -> + {connection_error, protocol_error, + 'The connection preface was invalid. (RFC7540 3.5)'} + end. + parse(<< Len:24, _/bits >>, MaxFrameSize) when Len > MaxFrameSize -> {connection_error, frame_size_error, 'The frame size exceeded SETTINGS_MAX_FRAME_SIZE. (RFC7540 4.2)'}; parse(Data, _) -> -- cgit v1.2.3