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

Support underscore in host names for Rack 2.2 (Fixes #2070) #2071

Merged
merged 1 commit into from
Apr 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def split_header(value)
(?<ip4>[\d\.]+)
|
# A hostname:
(?<name>[a-zA-Z0-9\.\-]+)
(?<name>[a-zA-Z0-9\.\-_]+)
)
# The optional port:
(:(?<port>\d+))?
Expand Down
9 changes: 9 additions & 0 deletions test/spec_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ class RackRequestTest < Minitest::Spec
req.host.must_equal "123foo.example.com"
req.hostname.must_equal "123foo.example.com"

req = make_request \
Rack::MockRequest.env_for("/", "HTTP_HOST" => "some_service:3001")
req.host.must_equal "some_service"
req.hostname.must_equal "some_service"

req = make_request \
Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org", "SERVER_PORT" => "9292")
req.host.must_equal "example.org"
Expand Down Expand Up @@ -156,6 +161,10 @@ class RackRequestTest < Minitest::Spec
Rack::MockRequest.env_for("/", "HTTP_HOST" => "www2.example.org:81")
req.port.must_equal 81

req = make_request \
Rack::MockRequest.env_for("/", "HTTP_HOST" => "some_service:3001")
req.port.must_equal 3001

req = make_request \
Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org", "SERVER_PORT" => "9292")
req.port.must_equal 9292
Expand Down