Skip to content

Commit d800ec3

Browse files
authored
Merge pull request #14618 from rabbitmq/mergify/bp/v4.2.x/pr-14616
AMQP1.0 client: Support HTTP/2 Websocket (backport #14616)
2 parents 75d8beb + f1f93d4 commit d800ec3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

deps/amqp10_client/src/amqp10_client_socket.erl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,27 @@
2929
amqp10_client_connection:connection_config()) ->
3030
{ok, socket()} | {error, any()}.
3131
connect(Host, Port, #{ws_path := Path} = Opts) ->
32+
GunOpts0 = maps:get(ws_opts, Opts, #{}),
33+
HTTP2Opts = maps:get(http2_opts, GunOpts0, #{}),
34+
GunOpts1 = GunOpts0#{http2_opts => HTTP2Opts#{notify_settings_changed => true}},
3235
GunOpts = maps:merge(#{tcp_opts => [{nodelay, true}]},
33-
maps:get(ws_opts, Opts, #{})),
36+
GunOpts1),
3437
maybe
3538
{ok, _Started} ?= application:ensure_all_started(gun),
3639
{ok, Pid} ?= gun:open(Host, Port, GunOpts),
3740
MRef = monitor(process, Pid),
38-
{ok, _HttpVsn} ?= gun:await_up(Pid, MRef),
41+
{ok, HttpVsn} ?= gun:await_up(Pid, MRef),
42+
ok ?= case HttpVsn of
43+
http ->
44+
ok;
45+
http2 ->
46+
receive
47+
{gun_notify, Pid, settings_changed, #{enable_connect_protocol := true}} ->
48+
ok
49+
after 5000 ->
50+
{error, {ws_enable_connect_protocol, timeout}}
51+
end
52+
end,
3953
{ok, StreamRef} ?= ws_upgrade(Pid, Path),
4054
{ok, {ws, Pid, StreamRef}}
4155
end;
@@ -97,5 +111,6 @@ close({tcp, Socket}) ->
97111
gen_tcp:close(Socket);
98112
close({ssl, Socket}) ->
99113
ssl:close(Socket);
100-
close({ws, Pid, _Ref}) ->
114+
close({ws, Pid, Ref}) ->
115+
gun:ws_send(Pid, Ref, close),
101116
gun:shutdown(Pid).

0 commit comments

Comments
 (0)