Skip to content

Commit 7fd1f9d

Browse files
committed
Wait for HTTP/2 server to enable connect protocol
This is a consequence of updating Mint to 1.5.0+ - the SETTINGS frame is now handled asynchronously (for the sake of latency) and Mint returns default values until it arrives. So we need to wait for that frame to arrive and be processed before upgrading an HTTP/2 WebSocket.
1 parent 4a1403e commit 7fd1f9d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/mint/web_socket_test.exs

+19
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,29 @@ defmodule Mint.WebSocketTest do
119119
end
120120
end
121121

122+
@doc !"""
123+
In Mint 1.5.0+, Mint handles the SETTINGS frame from the server asynchronously
124+
and returns default values for server settings until it is received. So we must
125+
wait for the server to send the SETTINGS frame enabling the connect protocol.
126+
"""
127+
defp wait_for_connect_protocol(conn) do
128+
if HTTP2.get_server_setting(conn, :enable_connect_protocol) do
129+
conn
130+
else
131+
receive do
132+
message ->
133+
{:ok, conn, []} = HTTP2.stream(conn, message)
134+
wait_for_connect_protocol(conn)
135+
end
136+
end
137+
end
138+
122139
describe "given an HTTP/2 WebSocket connection to an echo server" do
123140
setup do
124141
{:ok, conn} = HTTP2.connect(:http, "localhost", 7070)
125142

143+
conn = wait_for_connect_protocol(conn)
144+
126145
{:ok, conn, ref} =
127146
WebSocket.upgrade(:ws, conn, "/", [], extensions: [WebSocket.PerMessageDeflate])
128147

0 commit comments

Comments
 (0)