aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http2.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cow_http2.erl')
-rw-r--r--src/cow_http2.erl19
1 files changed, 19 insertions, 0 deletions
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),
+ <<Preface:Len/binary, _/bits>> = <<"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, _) ->