mirror of https://github.com/python/cpython
Patch from Paul Schreiber <paul@commerceflow.com>:
Patch description ----------------- This addresses four issues: (1) usernames and passwords in urls with special characters are now decoded properly. i.e. http://foo%2C:bar@www.whatever.com/ (2) Basic Auth support has been added to HTTPS, like it was in HTTP. (3) Version 1.92 sent the POSTed data, but did not deal with errors (HTTP responses other than 200) properly. HTTPS now behaves the same way HTTP does. (4) made URL-checking beahve the same way with HTTPS as it does with HTTP (changed == to !=).
This commit is contained in:
parent
9087688581
commit
567ca8e732
|
@ -302,15 +302,24 @@ class URLopener:
|
||||||
def open_https(self, url, data=None):
|
def open_https(self, url, data=None):
|
||||||
"""Use HTTPS protocol."""
|
"""Use HTTPS protocol."""
|
||||||
import httplib
|
import httplib
|
||||||
|
user_passwd = None
|
||||||
if type(url) is type(""):
|
if type(url) is type(""):
|
||||||
host, selector = splithost(url)
|
host, selector = splithost(url)
|
||||||
user_passwd, host = splituser(host)
|
if host:
|
||||||
|
user_passwd, host = splituser(host)
|
||||||
|
host = unquote(host)
|
||||||
|
realhost = host
|
||||||
else:
|
else:
|
||||||
host, selector = url
|
host, selector = url
|
||||||
urltype, rest = splittype(selector)
|
urltype, rest = splittype(selector)
|
||||||
if string.lower(urltype) == 'https':
|
url = rest
|
||||||
|
user_passwd = None
|
||||||
|
if string.lower(urltype) != 'https':
|
||||||
|
realhost = None
|
||||||
|
else:
|
||||||
realhost, rest = splithost(rest)
|
realhost, rest = splithost(rest)
|
||||||
user_passwd, realhost = splituser(realhost)
|
if realhost:
|
||||||
|
user_passwd, realhost = splituser(realhost)
|
||||||
if user_passwd:
|
if user_passwd:
|
||||||
selector = "%s://%s%s" % (urltype, realhost, rest)
|
selector = "%s://%s%s" % (urltype, realhost, rest)
|
||||||
#print "proxy via https:", host, selector
|
#print "proxy via https:", host, selector
|
||||||
|
@ -331,6 +340,7 @@ class URLopener:
|
||||||
else:
|
else:
|
||||||
h.putrequest('GET', selector)
|
h.putrequest('GET', selector)
|
||||||
if auth: h.putheader('Authorization: Basic %s' % auth)
|
if auth: h.putheader('Authorization: Basic %s' % auth)
|
||||||
|
if realhost: h.putheader('Host', realhost)
|
||||||
for args in self.addheaders: apply(h.putheader, args)
|
for args in self.addheaders: apply(h.putheader, args)
|
||||||
h.endheaders()
|
h.endheaders()
|
||||||
if data is not None:
|
if data is not None:
|
||||||
|
@ -340,8 +350,11 @@ class URLopener:
|
||||||
if errcode == 200:
|
if errcode == 200:
|
||||||
return addinfourl(fp, headers, url)
|
return addinfourl(fp, headers, url)
|
||||||
else:
|
else:
|
||||||
return self.http_error(url, fp, errcode, errmsg, headers)
|
if data is None:
|
||||||
|
return self.http_error(url, fp, errcode, errmsg, headers)
|
||||||
|
else:
|
||||||
|
return self.http_error(url, fp, errcode, errmsg, headers, data)
|
||||||
|
|
||||||
def open_gopher(self, url):
|
def open_gopher(self, url):
|
||||||
"""Use Gopher protocol."""
|
"""Use Gopher protocol."""
|
||||||
import gopherlib
|
import gopherlib
|
||||||
|
@ -872,7 +885,7 @@ def splituser(host):
|
||||||
_userprog = re.compile('^([^@]*)@(.*)$')
|
_userprog = re.compile('^([^@]*)@(.*)$')
|
||||||
|
|
||||||
match = _userprog.match(host)
|
match = _userprog.match(host)
|
||||||
if match: return match.group(1, 2)
|
if match: return map(unquote, match.group(1, 2))
|
||||||
return None, host
|
return None, host
|
||||||
|
|
||||||
_passwdprog = None
|
_passwdprog = None
|
||||||
|
|
Loading…
Reference in New Issue