From 048224a888b3331796e66dd974c6d75234e09036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 27 Jul 2020 17:24:16 +0200 Subject: Add HTTP/2 CONNECT tests with Cowboy as origin --- src/gun.erl | 1 + src/gun_http.erl | 2 ++ src/gun_http2.erl | 21 ++++++++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gun.erl b/src/gun.erl index 00e2d82..8b0b78d 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -1464,6 +1464,7 @@ commands([{set_cookie, _, _, _, _}|Tail], State=#state{cookie_store=undefined}) commands([{set_cookie, _, _, Status, _}|Tail], State=#state{opts=#{cookie_ignore_informational := true}}) when Status >= 100, Status =< 199 -> commands(Tail, State); +%% @todo Make sure this works for proxied requests too. commands([{set_cookie, Authority, PathWithQs, _, Headers}|Tail], State=#state{ transport=Transport, cookie_store=Store0}) -> Scheme = case Transport of diff --git a/src/gun_http.erl b/src/gun_http.erl index 982df82..6b511a3 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -515,6 +515,8 @@ close_reason(closed) -> closed; close_reason(Reason) -> {closed, Reason}. %% @todo Do we want an event for this? +%% +%% @todo Need to propagate stream closing to tunneled streams. close_streams(_, [], _) -> ok; close_streams(State, [#stream{is_alive=false}|Tail], Reason) -> diff --git a/src/gun_http2.erl b/src/gun_http2.erl index 7b6d1eb..b1dc1e6 100644 --- a/src/gun_http2.erl +++ b/src/gun_http2.erl @@ -330,13 +330,24 @@ data_frame(State, StreamID, IsFin, Data, EvHandler, EvHandlerState0) -> %% This means that #stream{} must contain both the user-facing StreamRef and the reference. - %% @todo Commands. - {{state, ProtoState}, EvHandlerState} = Protocol:handle(Data, ProtoState0, - EvHandler, EvHandlerState0), - {store_stream(State, Stream#stream{tunnel={Protocol, ProtoState, TunnelInfo}}), - EvHandlerState} + {Commands, EvHandlerState} = Protocol:handle(Data, ProtoState0, EvHandler, EvHandlerState0), + {tunnel_commands(Commands, Stream, Protocol, TunnelInfo, State), EvHandlerState} end. +tunnel_commands(Command, Stream, Protocol, TunnelInfo, State) when not is_list(Command) -> + tunnel_commands([Command], Stream, Protocol, TunnelInfo, State); +tunnel_commands([], Stream, _, _, State) -> + store_stream(State, Stream); +tunnel_commands([{state, ProtoState}|Tail], Stream, Protocol, TunnelInfo, State) -> + tunnel_commands(Tail, Stream#stream{tunnel={Protocol, ProtoState, TunnelInfo}}, + Protocol, TunnelInfo, State); +tunnel_commands([SetCookie={set_cookie, _, _, _, _}|Tail], Stream, Protocol, TunnelInfo, + State=#http2_state{commands_queue=Queue}) -> + tunnel_commands(Tail, Stream, Protocol, TunnelInfo, + State#http2_state{commands_queue=[SetCookie|Queue]}); +tunnel_commands([{active, true}|Tail], Stream, Protocol, TunnelInfo, State) -> + tunnel_commands(Tail, Stream, Protocol, TunnelInfo, State). + data_frame(State0, StreamID, IsFin, Data, EvHandler, EvHandlerState0, Stream=#stream{ref=StreamRef, reply_to=ReplyTo, flow=Flow0, handler_state=Handlers0}) -> {ok, Dec, Handlers} = gun_content_handler:handle(IsFin, Data, Handlers0), -- cgit v1.2.3