From c6d26f4b3bd21ecc80d6040cef290a2c0fc165db Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 14 Jun 2024 12:20:34 -0400 Subject: [PATCH] Wait for HTTP/2 server to enable connect protocol (Mint 1.5.0+) 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. --- test/mint/web_socket_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/mint/web_socket_test.exs b/test/mint/web_socket_test.exs index 7c20e9e1..12f72167 100644 --- a/test/mint/web_socket_test.exs +++ b/test/mint/web_socket_test.exs @@ -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])