diff options
author | Loïc Hoguin <[email protected]> | 2019-09-26 13:16:56 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-09-26 13:20:28 +0200 |
commit | 00cc1f385f94823a0684deee001b643091e235b0 (patch) | |
tree | 6e5406fb62b71b17b29f1de42ccbe01c8c191547 /test/raw_SUITE.erl | |
parent | d86d55c1f90b37d991e20ad0f1ac37b1e38b36e1 (diff) | |
download | gun-00cc1f385f94823a0684deee001b643091e235b0.tar.gz gun-00cc1f385f94823a0684deee001b643091e235b0.tar.bz2 gun-00cc1f385f94823a0684deee001b643091e235b0.zip |
Add reply_to option to ws_upgrade; remove notowner entirely
The reply_to option is also propagated when we switch protocols.
Diffstat (limited to 'test/raw_SUITE.erl')
-rw-r--r-- | test/raw_SUITE.erl | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/raw_SUITE.erl b/test/raw_SUITE.erl index 6a843ea..18ab3b5 100644 --- a/test/raw_SUITE.erl +++ b/test/raw_SUITE.erl @@ -159,6 +159,33 @@ do_connect_raw(OriginTransport, ProxyTransport) -> }]} = gun:info(ConnPid), gun:close(ConnPid). +connect_raw_reply_to(_) -> + doc("When using CONNECT to establish a connection with the reply_to option set, " + "Gun must honor this option in the raw protocol."), + Self = self(), + ReplyTo = spawn(fun() -> + {ConnPid, StreamRef} = receive Msg -> Msg after 1000 -> error(timeout) end, + {response, fin, 200, _} = gun:await(ConnPid, StreamRef), + Self ! {self(), ready}, + {data, nofin, <<"Hello world!">>} = gun:await(ConnPid, undefined), + Self ! {self(), ok} + end), + {ok, OriginPid, OriginPort} = init_origin(tcp, raw, fun do_echo/3), + {ok, ProxyPid, ProxyPort} = rfc7231_SUITE:do_proxy_start(tcp), + {ok, ConnPid} = gun:open("localhost", ProxyPort), + {ok, http} = gun:await_up(ConnPid), + StreamRef = gun:connect(ConnPid, #{ + host => "localhost", + port => OriginPort, + protocols => [raw] + }, [], #{reply_to => ReplyTo}), + ReplyTo ! {ConnPid, StreamRef}, + {request, <<"CONNECT">>, _, 'HTTP/1.1', _} = receive_from(ProxyPid), + handshake_completed = receive_from(OriginPid), + receive {ReplyTo, ready} -> ok after 1000 -> error(timeout) end, + gun:data(ConnPid, undefined, nofin, <<"Hello world!">>), + receive {ReplyTo, ok} -> gun:close(ConnPid) after 1000 -> error(timeout) end. + http11_upgrade_raw_tcp(_) -> doc("Use the HTTP Upgrade mechanism to switch to the raw protocol over TCP."), do_http11_upgrade_raw(tcp). @@ -202,6 +229,40 @@ do_http11_upgrade_raw(OriginTransport) -> } = gun:info(ConnPid), gun:close(ConnPid). +http11_upgrade_raw_reply_to(_) -> + doc("When upgrading an HTTP/1.1 connection with the reply_to option set, " + "Gun must honor this option in the raw protocol."), + Self = self(), + ReplyTo = spawn(fun() -> + {ConnPid, StreamRef} = receive Msg -> Msg after 1000 -> error(timeout) end, + {upgrade, [<<"custom/1.0">>], _} = gun:await(ConnPid, StreamRef), + Self ! {self(), ready}, + {data, nofin, <<"Hello world!">>} = gun:await(ConnPid, undefined), + Self ! {self(), ok} + end), + {ok, OriginPid, OriginPort} = init_origin(tcp, raw, + fun (Parent, ClientSocket, ClientTransport) -> + %% We skip the request and send a 101 response unconditionally. + {ok, _} = ClientTransport:recv(ClientSocket, 0, 5000), + ClientTransport:send(ClientSocket, + "HTTP/1.1 101 Switching Protocols\r\n" + "Connection: upgrade\r\n" + "Upgrade: custom/1.0\r\n" + "\r\n"), + do_echo(Parent, ClientSocket, ClientTransport) + end), + {ok, ConnPid} = gun:open("localhost", OriginPort), + {ok, http} = gun:await_up(ConnPid), + handshake_completed = receive_from(OriginPid), + StreamRef = gun:get(ConnPid, "/", #{ + <<"connection">> => <<"upgrade">>, + <<"upgrade">> => <<"custom/1.0">> + }, #{reply_to => ReplyTo}), + ReplyTo ! {ConnPid, StreamRef}, + receive {ReplyTo, ready} -> ok after 1000 -> error(timeout) end, + gun:data(ConnPid, undefined, nofin, <<"Hello world!">>), + receive {ReplyTo, ok} -> gun:close(ConnPid) after 1000 -> error(timeout) end. + %% The origin server will echo everything back. do_echo(Parent, ClientSocket, ClientTransport) -> |