Skip to content

Commit

Permalink
Add nounce processing to HTTP/2 WebSockets for HTTP/1 proxy compatibi…
Browse files Browse the repository at this point in the history
…lity.
  • Loading branch information
ioquatix committed Sep 3, 2024
1 parent 534cad7 commit d817859
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/async/websocket/connect_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/async/websocket/upgrade_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d817859

Please sign in to comment.