From bb83a6ce33288c04250497318565ac499282c720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 26 Feb 2017 13:24:15 +0100 Subject: Unknown HTTP/2 frames are ignored --- src/cowboy_http2.erl | 2 ++ test/rfc7540_SUITE.erl | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl index bbf400e..7cb564c 100644 --- a/src/cowboy_http2.erl +++ b/src/cowboy_http2.erl @@ -231,6 +231,8 @@ parse(State=#state{local_settings=#{max_frame_size := MaxFrameSize}, {continuation, _, _, _} -> parse(continuation_frame(State, Frame), Rest) end; + {ignore, Rest} -> + parse(State, Rest); {stream_error, StreamID, Reason, Human, Rest} -> parse(stream_reset(State, StreamID, {stream_error, Reason, Human}), Rest); Error = {connection_error, _, _} -> diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl index d99e9f2..9d25bdd 100644 --- a/test/rfc7540_SUITE.erl +++ b/test/rfc7540_SUITE.erl @@ -809,6 +809,31 @@ prior_knowledge(Config) -> %% * Prior knowledge handshake fails (3.4) %% * ALPN selects HTTP/1.1 (3.3) +%% Frame format. + +ignore_unknown_frames(Config) -> + doc("Frames of unknown type must be ignored and discarded. (RFC7540 4.1)"), + {ok, Socket} = do_handshake(Config), + %% Send a POST request with a single DATA frame, + %% and an unknown frame type interleaved. + {HeadersBlock, _} = cow_hpack:encode([ + {<<":method">>, <<"POST">>}, + {<<":scheme">>, <<"http">>}, + {<<":authority">>, <<"localhost">>}, %% @todo Correct port number. + {<<":path">>, <<"/echo/read_body">>} + ]), + ok = gen_tcp:send(Socket, [ + cow_http2:headers(1, nofin, HeadersBlock), + << 10:24, 99:8, 0:40, 0:80 >>, + cow_http2:data(1, fin, << 0:100/unit:8 >>) + ]), + %% Receive a response with the same DATA frame. + {ok, << SkipLen:24, 1:8, _:8, 1:32 >>} = gen_tcp:recv(Socket, 9, 1000), + {ok, _} = gen_tcp:recv(Socket, SkipLen, 1000), + {ok, << 100:24, 0:8, 1:8, 1:32 >>} = gen_tcp:recv(Socket, 9, 1000), + {ok, << 0:100/unit:8 >>} = gen_tcp:recv(Socket, 100, 1000), + ok. + %% Frame size. max_frame_size_allow_exactly_default(Config) -> -- cgit v1.2.3