diff --git a/lib/protocol/rack/adapter/generic.rb b/lib/protocol/rack/adapter/generic.rb index 9869ac2..ac2aa48 100644 --- a/lib/protocol/rack/adapter/generic.rb +++ b/lib/protocol/rack/adapter/generic.rb @@ -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 diff --git a/lib/protocol/rack/adapter/rack2.rb b/lib/protocol/rack/adapter/rack2.rb index 5dd26c7..2b43639 100644 --- a/lib/protocol/rack/adapter/rack2.rb +++ b/lib/protocol/rack/adapter/rack2.rb @@ -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] diff --git a/lib/protocol/rack/adapter/rack3.rb b/lib/protocol/rack/adapter/rack3.rb index 6177a25..3f4c322 100644 --- a/lib/protocol/rack/adapter/rack3.rb +++ b/lib/protocol/rack/adapter/rack3.rb @@ -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: