Skip to content

Commit

Permalink
Add support for HTTP_UPGRADE protocol handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jun 14, 2024
1 parent 6399388 commit 1c504c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 14 additions & 0 deletions lib/protocol/rack/adapter/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ def call(request)
def failure_response(exception)
Protocol::HTTP::Response.for_exception(exception)
end

def self.extract_protocol(env, response, headers)
if protocol = response.protocol
# This is the newer mechanism for protocol upgrade:
if env['rack.protocol']
headers['rack.protocol'] = protocol

# Older mechanism for protocol upgrade:
elsif env[CGI::HTTP_UPGRADE]
headers['upgrade'] = protocol
headers['connection'] = 'upgrade'
end
end
end
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/protocol/rack/adapter/rack2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ def self.make_response(env, response)
# These interfaces should be largely compatible:
headers = response.headers.to_h

if protocol = response.protocol
headers['rack.protocol'] = protocol
end
self.extract_protocol(env, response, headers)

if body = response.body and body.stream?
if env[RACK_IS_HIJACK]
Expand Down
5 changes: 2 additions & 3 deletions lib/protocol/rack/adapter/rack3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ def wrap_headers(fields)
def self.make_response(env, response)
# These interfaces should be largely compatible:
headers = response.headers.to_h
if protocol = response.protocol
headers['rack.protocol'] = protocol
end

self.extract_protocol(env, response, headers)

if body = response.body and body.stream?
# Force streaming response:
Expand Down

0 comments on commit 1c504c6

Please sign in to comment.