aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cow_http2.erl11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cow_http2.erl b/src/cow_http2.erl
index a0d1297..c2dba8b 100644
--- a/src/cow_http2.erl
+++ b/src/cow_http2.erl
@@ -196,7 +196,7 @@ parse(<< 8:24, 6:8, _:7, 0:1, _:1, 0:31, Opaque:64, Rest/bits >>) ->
{ok, {ping, Opaque}, Rest};
parse(<< 8:24, 6:8, _:104, _/bits >>) ->
{connection_error, protocol_error, 'PING frames MUST NOT be associated with a stream. (RFC7540 6.7)'};
-parse(<< _:24, 6:8, _/bits >>) ->
+parse(<< Len:24, 6:8, _/bits >>) when Len =/= 8 ->
{connection_error, frame_size_error, 'PING frames MUST be 8 bytes wide. (RFC7540 6.7)'};
%%
%% GOAWAY frames.
@@ -233,6 +233,15 @@ parse(<< Len:24, 9:8, _:5, FlagEndHeaders:1, _:3, StreamID:31, HeaderBlockFragme
parse(_) ->
more.
+-ifdef(TEST).
+parse_ping_test() ->
+ Ping = ping(1234567890),
+ _ = [more = parse(binary:part(Ping, 0, I)) || I <- lists:seq(1, byte_size(Ping) - 1)],
+ {ok, {ping, 1234567890}, <<>>} = parse(Ping),
+ {ok, {ping, 1234567890}, << 42 >>} = parse(<< Ping/binary, 42 >>),
+ ok.
+-endif.
+
parse_fin(0) -> nofin;
parse_fin(1) -> fin.