mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Strip square brackets from IPv6 address.
This commit is contained in:
parent
82d0eecf42
commit
74a249e1a9
2 changed files with 10 additions and 3 deletions
|
@ -534,6 +534,8 @@ class HTTPConnection:
|
||||||
host = host[:i]
|
host = host[:i]
|
||||||
else:
|
else:
|
||||||
port = self.default_port
|
port = self.default_port
|
||||||
|
if host[0] == '[' and host[-1] == ']':
|
||||||
|
host = host[1:-1]
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
|
|
|
@ -118,12 +118,17 @@ def _test():
|
||||||
else:
|
else:
|
||||||
print "Expect InvalidURL"
|
print "Expect InvalidURL"
|
||||||
|
|
||||||
for hp in ("[fe80::207:e9ff:fe9b]:8000", "www.python.org:80",
|
for hp,h,p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000),
|
||||||
"www.python.org", "[fe80::207:e9ff:fe9b]"):
|
("www.python.org:80", "www.python.org", 80),
|
||||||
|
("www.python.org", "www.python.org", 80),
|
||||||
|
("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)):
|
||||||
try:
|
try:
|
||||||
h = httplib.HTTP(hp)
|
http = httplib.HTTP(hp)
|
||||||
except httplib.InvalidURL:
|
except httplib.InvalidURL:
|
||||||
print "InvalidURL raised erroneously"
|
print "InvalidURL raised erroneously"
|
||||||
|
c = http._conn
|
||||||
|
if h != c.host: raise AssertionError, ("Host incorrectly parsed", h, c.host)
|
||||||
|
if p != c.port: raise AssertionError, ("Port incorrectly parsed", p, c.host)
|
||||||
|
|
||||||
# test response with multiple message headers with the same field name.
|
# test response with multiple message headers with the same field name.
|
||||||
text = ('HTTP/1.1 200 OK\r\n'
|
text = ('HTTP/1.1 200 OK\r\n'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue