diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-02-06 16:45:23 +1300 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-02-08 00:52:30 +1300 |
commit | 7bcb6ceda3a1812fe04e340739adc08d1f90bd1e (patch) | |
tree | bf858a715a41807bba28e68d0961c661471f6203 | |
parent | a3380a8e64a3f8c1c3ee39da50a633e4e98e21a5 (diff) | |
download | rack-7bcb6ceda3a1812fe04e340739adc08d1f90bd1e.tar.gz |
Add specs to better match implementation of `URI.host` and `URI.hostname`.
u = URI("http://[::1]/bar")
p u.hostname #=> "::1"
p u.host #=> "[::1]"
-rw-r--r-- | test/spec_request.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/test/spec_request.rb b/test/spec_request.rb index f4980e23..0fc5abf9 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -114,27 +114,33 @@ class RackRequestTest < Minitest::Spec req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "www2.example.org") req.host.must_equal "www2.example.org" + req.hostname.must_equal "www2.example.org" req = make_request \ Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org", "SERVER_PORT" => "9292") req.host.must_equal "example.org" + req.hostname.must_equal "example.org" req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org:9292") req.host.must_equal "example.org" + req.hostname.must_equal "example.org" req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "[2001:db8:cafe::17]:47011") - req.host.must_equal "2001:db8:cafe::17" + req.host.must_equal "[2001:db8:cafe::17]" + req.hostname.must_equal "2001:db8:cafe::17" req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "2001:db8:cafe::17") - req.host.must_equal "2001:db8:cafe::17" + req.host.must_equal "[2001:db8:cafe::17]" + req.hostname.must_equal "2001:db8:cafe::17" env = Rack::MockRequest.env_for("/", "SERVER_ADDR" => "192.168.1.1", "SERVER_PORT" => "9292") env.delete("SERVER_NAME") req = make_request(env) req.host.must_equal "192.168.1.1" + req.hostname.must_equal "192.168.1.1" env = Rack::MockRequest.env_for("/") env.delete("SERVER_NAME") @@ -175,7 +181,7 @@ class RackRequestTest < Minitest::Spec Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org", "HTTP_X_FORWARDED_SSL" => "on") req.port.must_equal 443 - req = make_request \ + req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org", "HTTP_X_FORWARDED_PROTO" => "https") req.port.must_equal 443 @@ -227,7 +233,7 @@ class RackRequestTest < Minitest::Spec req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "2001:db8:cafe::17") - req.host_with_port.must_equal "2001:db8:cafe::17" + req.host_with_port.must_equal "[2001:db8:cafe::17]" req = make_request \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org", "SERVER_PORT" => "9393") |