From 21ff3ff256acc6c56e2ab35bb9712ea7b8ef6687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 27 Oct 2018 10:07:34 +0200 Subject: Fix small issues introduced in the previous commit --- src/cowboy_http2.erl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl index 5e50213..97f7c02 100644 --- a/src/cowboy_http2.erl +++ b/src/cowboy_http2.erl @@ -64,7 +64,7 @@ cert :: undefined | binary(), %% HTTP/2 state machine. - http2_init :: sequence | upgrade | complete, + http2_init :: sequence | settings | upgrade | complete, http2_machine :: cow_http2_machine:http2_machine(), %% Currently active HTTP/2 streams. Streams may be initiated either @@ -197,7 +197,7 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport, parse(State=#state{http2_init=sequence}, Data) -> case cow_http2:parse_sequence(Data) of {ok, Rest} -> - parse(State#state{http2_init=complete}, Rest); + parse(State#state{http2_init=settings}, Rest); more -> before_loop(State, Data); Error = {connection_error, _, _} -> @@ -247,6 +247,10 @@ frame(State=#state{http2_machine=HTTP2Machine0}, Frame) -> terminate(State#state{http2_machine=HTTP2Machine}, Error) end. +%% We use this opportunity to mark the HTTP/2 initialization +%% as complete if we were still waiting for a SETTINGS frame. +maybe_ack(State=#state{http2_init=settings}, Frame) -> + maybe_ack(State#state{http2_init=complete}, Frame); maybe_ack(State=#state{socket=Socket, transport=Transport}, Frame) -> case Frame of {settings, _} -> Transport:send(Socket, cow_http2:settings_ack()); @@ -417,7 +421,7 @@ ignored_frame(State=#state{http2_machine=HTTP2Machine0}) -> %% HTTP/2 timeouts. -timeout(State=#state{http2_machine=HTTP2Machine0}, TRef, Name) -> +timeout(State=#state{http2_machine=HTTP2Machine0}, Name, TRef) -> case cow_http2_machine:timeout(Name, TRef, HTTP2Machine0) of {ok, HTTP2Machine} -> State#state{http2_machine=HTTP2Machine}; -- cgit v1.2.3