aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-10-26 18:50:10 +0200
committerLoïc Hoguin <[email protected]>2018-10-26 18:50:10 +0200
commita670e3bf723eae094f82520f38cad40c609b1cd2 (patch)
treebd49ef416d990d482c7d8a58ace13af20c15c6ca
parentb461b119e78e4e09bb28b186b09da7ed4a86a0dd (diff)
downloadcowlib-a670e3bf723eae094f82520f38cad40c609b1cd2.tar.gz
cowlib-a670e3bf723eae094f82520f38cad40c609b1cd2.tar.bz2
cowlib-a670e3bf723eae094f82520f38cad40c609b1cd2.zip
Add cow_http2:parse_sequence/1
-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, _) ->