Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose HTTP_UPGRADE header when translating request to Rack environment. #8

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/protocol/rack/adapter/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def unwrap_request(request, env)

self.unwrap_headers(request.headers, env)

# For the sake of compatibility, we set the `HTTP_UPGRADE` header to the requested protocol.
if protocol = request.protocol and request.version.start_with?('http/1')
env[CGI::HTTP_UPGRADE] = Array(protocol).join(",")
end

# HTTP/2 prefers `:authority` over `host`, so we do this for backwards compatibility.
env[CGI::HTTP_HOST] ||= request.authority

Expand Down
1 change: 0 additions & 1 deletion lib/protocol/rack/adapter/rack2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def self.make_response(env, response)

if protocol = response.protocol
headers['rack.protocol'] = protocol
# headers['upgrade'] = protocol
end

if body = response.body and body.stream?
Expand Down
1 change: 1 addition & 0 deletions lib/protocol/rack/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Rack
# CGI keys <https://tools.ietf.org/html/rfc3875#section-4.1>:
module CGI
HTTP_HOST = 'HTTP_HOST'
HTTP_UPGRADE = "HTTP_UPGRADE"
PATH_INFO = 'PATH_INFO'
REQUEST_METHOD = 'REQUEST_METHOD'
REQUEST_PATH = 'REQUEST_PATH'
Expand Down
5 changes: 2 additions & 3 deletions lib/protocol/rack/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'protocol/http/request'
require 'protocol/http/headers'

require_relative 'constants'
require_relative 'body/input_wrapper'

module Protocol
Expand All @@ -30,12 +31,10 @@ def initialize(env)
)
end

HTTP_UPGRADE = 'HTTP_UPGRADE'

def self.protocol(env)
if protocols = env['rack.protocol']
return Array(protocols)
elsif protocols = env[HTTP_UPGRADE]
elsif protocols = env[CGI::HTTP_UPGRADE]
return protocols.split(/\s*,\s*/)
end
end
Expand Down
Loading