diff --git a/lib/async/websocket/connect_response.rb b/lib/async/websocket/connect_response.rb index b3ef2f0..987e830 100644 --- a/lib/async/websocket/connect_response.rb +++ b/lib/async/websocket/connect_response.rb @@ -19,6 +19,11 @@ def initialize(request, headers = nil, protocol: nil, &block) headers.add(SEC_WEBSOCKET_PROTOCOL, protocol) end + # For compatibility with HTTP/1 websockets proxied over HTTP/2, we process the accept nounce here: + if accept_nounce = request.headers[SEC_WEBSOCKET_KEY]&.first + headers.add(SEC_WEBSOCKET_ACCEPT, Nounce.accept_digest(accept_nounce)) + end + body = Async::HTTP::Body::Hijack.wrap(request, &block) super(request.version, 200, headers, body) diff --git a/lib/async/websocket/upgrade_request.rb b/lib/async/websocket/upgrade_request.rb index 2e03bce..b0c8553 100644 --- a/lib/async/websocket/upgrade_request.rb +++ b/lib/async/websocket/upgrade_request.rb @@ -81,6 +81,7 @@ def call(connection) raise ProtocolError, "Invalid accept digest, expected #{expected_accept_digest.inspect}, got #{accept_digest.inspect}!" end end + verified = accept_digest && Array(response.protocol).map(&:downcase) == %w(websocket) && response.headers['connection']&.include?('upgrade') return Wrapper.new(response, verified: verified)