]> granicus.if.org Git - python/commitdiff
RFE #1472176: In httplib, don't encode the netloc and hostname with "idna" if not...
authorGeorg Brandl <georg@python.org>
Wed, 3 May 2006 18:03:22 +0000 (18:03 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 3 May 2006 18:03:22 +0000 (18:03 +0000)
Lib/httplib.py

index b4bd536c6cc2d02c3223ec199622c4ecbcb68e3b..36381de4693b65e22116ce785ea14c40ae6b711f 100644 (file)
@@ -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