summaryrefslogtreecommitdiff
path: root/test/net
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-21 20:36:07 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-21 20:36:07 +0000
commit570b766901c1a80f5a317012eb81ee9d1f301073 (patch)
tree14d373b6b3a8f52d66970279004a545b174cc01e /test/net
parent34a3668c30753dcd2632aaf84d3ee5d29599eac1 (diff)
* lib/net/http.rb: Requests may be created with a URI which sets the
Host header. Responses contain the requested URI for easier redirect following. [ruby-trunk - Feature #6482] * lib/net/http/generic_request.rb: ditto. * lib/net/http/response.rb: ditto.j * NEWS (net/http): Updated for above. * test/net/http/test_http.rb: Tests for above. * test/net/http/test_http.rb: ditto. * test/net/http/test_httpresponse.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net')
-rw-r--r--test/net/http/test_http.rb48
-rw-r--r--test/net/http/test_httpresponse.rb15
2 files changed, 63 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index 0dfb462..fef010a 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -409,6 +409,8 @@ module TestNetHTTP_version_1_2_methods
_test_request__HEAD http
_test_request__POST http
_test_request__stream_body http
+ _test_request__uri http
+ _test_request__uri_host http
}
end
@@ -488,6 +490,51 @@ module TestNetHTTP_version_1_2_methods
assert_equal data, res.body
end
+ def _test_request__path(http)
+ uri = URI 'https://example/'
+ req = Net::HTTP::Get.new('/')
+
+ res = http.request(req)
+
+ assert_kind_of URI::Generic, req.uri
+
+ refute_equal uri, req.uri
+
+ assert_equal uri, res.uri
+
+ refute_same uri, req.uri
+ refute_same req.uri, res.uri
+ end
+
+ def _test_request__uri(http)
+ uri = URI 'https://example/'
+ req = Net::HTTP::Get.new(uri)
+
+ res = http.request(req)
+
+ assert_kind_of URI::Generic, req.uri
+
+ refute_equal uri, req.uri
+
+ assert_equal req.uri, res.uri
+
+ refute_same uri, req.uri
+ refute_same req.uri, res.uri
+ end
+
+ def _test_request__uri_host(http)
+ uri = URI 'http://example/'
+
+ req = Net::HTTP::Get.new(uri)
+ req['host'] = 'other.example'
+
+ res = http.request(req)
+
+ assert_kind_of URI::Generic, req.uri
+
+ assert_equal URI("http://example:#{http.port}"), res.uri
+ end
+
def test_send_request
start {|http|
_test_send_request__GET http
@@ -837,3 +884,4 @@ class TestNetHTTPLocalBind < Test::Unit::TestCase
assert_equal(http.local_port, res.body)
end
end
+
diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb
index a4f242d..121b81f 100644
--- a/test/net/http/test_httpresponse.rb
+++ b/test/net/http/test_httpresponse.rb
@@ -203,6 +203,21 @@ EOS
assert_equal 'hello', body
end
+ def test_uri_equals
+ uri = URI 'http://example'
+
+ response = Net::HTTPResponse.new '1.1', 200, 'OK'
+
+ response.uri = nil
+
+ assert_nil response.uri
+
+ response.uri = uri
+
+ assert_equal uri, response.uri
+ refute_same uri, response.uri
+ end
+
private
def dummy_io(str)