summaryrefslogtreecommitdiffstats
path: root/Lib/httplib.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-05-03 18:03:22 (GMT)
committerGeorg Brandl <georg@python.org>2006-05-03 18:03:22 (GMT)
commita2ac2ef44f67006edc694ef8281cb42b5cfddc7b (patch)
tree28ac6cd7c994cde674157be7090db3c8152980ba /Lib/httplib.py
parent7377ad2ecd77ed70137de8975e04e0aaa87d37c9 (diff)
downloadcpython-a2ac2ef44f67006edc694ef8281cb42b5cfddc7b.zip
cpython-a2ac2ef44f67006edc694ef8281cb42b5cfddc7b.tar.gz
cpython-a2ac2ef44f67006edc694ef8281cb42b5cfddc7b.tar.bz2
RFE #1472176: In httplib, don't encode the netloc and hostname with "idna" if not necessary.
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r--Lib/httplib.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index b4bd536..36381de 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -796,11 +796,20 @@ class HTTPConnection:
nil, netloc, nil, nil, nil = urlsplit(url)
if netloc:
- self.putheader('Host', netloc.encode("idna"))
- elif self.port == HTTP_PORT:
- self.putheader('Host', self.host.encode("idna"))
+ try:
+ netloc_enc = netloc.encode("ascii")
+ except UnicodeEncodeError:
+ netloc_enc = netloc.encode("idna")
+ self.putheader('Host', netloc_enc)
else:
- self.putheader('Host', "%s:%s" % (self.host.encode("idna"), self.port))
+ try:
+ host_enc = self.host.encode("ascii")
+ except UnicodeEncodeError:
+ host_enc = self.host.encode("idna")
+ if self.port == HTTP_PORT:
+ self.putheader('Host', host_enc)
+ else:
+ self.putheader('Host', "%s:%s" % (host_enc, self.port))
# note: we are assuming that clients will not attempt to set these
# headers since *this* library must deal with the