aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gun_http2.erl13
-rw-r--r--test/fake_transport.erl4
-rw-r--r--test/gun_http2_test.erl8
3 files changed, 20 insertions, 5 deletions
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 38017b3..41ffc2d 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -103,18 +103,21 @@ init(Owner, Socket, Transport, Opts) ->
handle(Data, State=#http2_state{buffer=Buffer}) ->
parse(<< Buffer/binary, Data/binary >>, State#http2_state{buffer= <<>>}).
-parse(Data0, State=#http2_state{buffer=Buffer}) ->
+parse(Data0, State0=#http2_state{buffer=Buffer}) ->
%% @todo Parse states: Preface. Continuation.
Data = << Buffer/binary, Data0/binary >>,
case cow_http2:parse(Data) of
{ok, Frame, Rest} ->
- parse(Rest, frame(Frame, State));
+ case frame(Frame, State0) of
+ close -> close;
+ State1 -> parse(Rest, State1)
+ end;
{stream_error, StreamID, Reason, Human, Rest} ->
- parse(Rest, stream_reset(State, StreamID, {stream_error, Reason, Human}));
+ parse(Rest, stream_reset(State0, StreamID, {stream_error, Reason, Human}));
Error = {connection_error, _, _} ->
- terminate(State, Error);
+ terminate(State0, Error);
more ->
- State#http2_state{buffer=Data}
+ State0#http2_state{buffer=Data}
end.
%% DATA frame.
diff --git a/test/fake_transport.erl b/test/fake_transport.erl
new file mode 100644
index 0000000..80e9afd
--- /dev/null
+++ b/test/fake_transport.erl
@@ -0,0 +1,4 @@
+-module(fake_transport).
+-compile(export_all).
+
+send(Socket, Message) -> ok.
diff --git a/test/gun_http2_test.erl b/test/gun_http2_test.erl
new file mode 100644
index 0000000..1dd4d68
--- /dev/null
+++ b/test/gun_http2_test.erl
@@ -0,0 +1,8 @@
+-module(gun_http2_test).
+-include_lib("eunit/include/eunit.hrl").
+
+handle_go_away_test() ->
+ State = gun_http2:init(self(), socket, fake_transport, #{}),
+ Data = <<0,0,22,7,0,0,0,0,0,0,0,0,0,0,0,0,11,116,111,111,95,109,97,110,121,95,112,105,110,103,115>>,
+ Result = gun_http2:handle(Data, State),
+ ?assertEqual(close, Result).