Skip to content

Commit

Permalink
Support underscore in host names for Rack 2.2 (Fixes #2070) (#2071)
Browse files Browse the repository at this point in the history
This makes Rack 2.2 behavior similar to Rack 2.1 and Rack 3.0 in
regards to underscore in host names.
  • Loading branch information
jeremyevans committed Apr 24, 2023
1 parent 70185aa commit e5a30bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit e5a30bf

Please sign in to comment.