зеркало из https://github.com/github/ruby.git
Raise ArgumentError if host component is nil
From: oss92 <mohamed.o.alnagdy@gmail.com> fix https://github.com/ruby/ruby/pull/1278 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
897af5dfcd
Коммит
0f7b26ab4e
|
@ -14,6 +14,8 @@ class Net::HTTPGenericRequest
|
||||||
@response_has_body = resbody
|
@response_has_body = resbody
|
||||||
|
|
||||||
if URI === uri_or_path then
|
if URI === uri_or_path then
|
||||||
|
raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
|
||||||
|
raise ArgumentError, "no host component for URI" unless uri_or_path.hostname
|
||||||
@uri = uri_or_path.dup
|
@uri = uri_or_path.dup
|
||||||
host = @uri.hostname.dup
|
host = @uri.hostname.dup
|
||||||
host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port
|
host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port
|
||||||
|
|
|
@ -65,6 +65,18 @@ class HTTPRequestTest < Test::Unit::TestCase
|
||||||
'Bug #7381 - do not decode content if the user overrides'
|
'Bug #7381 - do not decode content if the user overrides'
|
||||||
end if Net::HTTP::HAVE_ZLIB
|
end if Net::HTTP::HAVE_ZLIB
|
||||||
|
|
||||||
|
def test_initialize_GET_uri
|
||||||
|
req = Net::HTTP::Get.new(URI("http://example.com/foo"))
|
||||||
|
assert_equal "/foo", req.path
|
||||||
|
assert_equal "example.com", req['Host']
|
||||||
|
|
||||||
|
req = Net::HTTP::Get.new(URI("https://example.com/foo"))
|
||||||
|
assert_equal "/foo", req.path
|
||||||
|
assert_equal "example.com", req['Host']
|
||||||
|
|
||||||
|
assert_raise(ArgumentError){ Net::HTTP::Get.new(URI("urn:ietf:rfc:7231")) }
|
||||||
|
end
|
||||||
|
|
||||||
def test_header_set
|
def test_header_set
|
||||||
req = Net::HTTP::Get.new '/'
|
req = Net::HTTP::Get.new '/'
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче