Skip to content

Commit

Permalink
Wait for HTTP/2 server to enable connect protocol (Mint 1.5.0+)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis committed Jun 14, 2024
1 parent 5fa0626 commit c6d26f4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/mint/web_socket_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,29 @@ defmodule Mint.WebSocketTest do
end
end

@doc !"""
In Mint 1.5.0+, Mint handles the SETTINGS frame from the server asynchronously
and returns default values for server settings until it is received. So we must
wait for the server to send the SETTINGS frame enabling the connect protocol.
"""
defp wait_for_connect_protocol(conn) do
if HTTP2.get_server_setting(conn, :enable_connect_protocol) do
conn
else
receive do
message ->
{:ok, conn, []} = HTTP2.stream(conn, message)
wait_for_connect_protocol(conn)
end
end
end

describe "given an HTTP/2 WebSocket connection to an echo server" do
setup do
{:ok, conn} = HTTP2.connect(:http, "localhost", 7070)

conn = wait_for_connect_protocol(conn)

{:ok, conn, ref} =
WebSocket.upgrade(:ws, conn, "/", [], extensions: [WebSocket.PerMessageDeflate])

Expand Down

0 comments on commit c6d26f4

Please sign in to comment.