8000 Add nounce processing to HTTP/2 WebSockets for HTTP/1 proxy compatibi… · socketry/async-websocket@d817859 · GitHub
[go: up one dir, main page]

Skip to content

Commit d817859

Browse files
committed
Add nounce processing to HTTP/2 WebSockets for HTTP/1 proxy compatibility.
1 parent 534cad7 commit d817859

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/async/websocket/connect_response.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def initialize(request, headers = nil, protocol: nil, &block)
1919
headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
2020
end
2121

22+
# For compatibility with HTTP/1 websockets proxied over HTTP/2, we process the accept nounce here:
23+
if accept_nounce = request.headers[SEC_WEBSOCKET_KEY]&.first
24+
headers.add(SEC_WEBSOCKET_ACCEPT, Nounce.accept_digest(accept_nounce))
25+
end
26+
2227
body = Async::HTTP::Body::Hijack.wrap(request, &block)
2328

2429
super(request.version, 200, headers, body)

lib/async/websocket/upgrade_request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def call(connection)
8181
raise ProtocolError, "Invalid accept digest, expected #{expected_accept_digest.inspect}, got #{accept_digest.inspect}!"
8282
end
8383
end
84+
8485
verified = accept_digest && Array(response.protocol).map(&:downcase) == %w(websocket) && response.headers['connection']&.include?('upgrade')
8586

8687
return Wrapper.new(response, verified: verified)

0 commit comments

Comments
 (0)
0