mirror of https://github.com/python/cpython
merge from 3.2 - fix urlopen behavior on sites which do not send (or obsfuscates) Connection: Close header.
This commit is contained in:
parent
d8b1723965
commit
7d7702b581
|
@ -186,6 +186,14 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
opener.open(request)
|
opener.open(request)
|
||||||
self.assertEqual(request.get_header('User-agent'),'Test-Agent')
|
self.assertEqual(request.get_header('User-agent'),'Test-Agent')
|
||||||
|
|
||||||
|
def test_sites_no_connection_close(self):
|
||||||
|
# Some sites do not send Connection: close header.
|
||||||
|
# Verify that those work properly. (#issue12576)
|
||||||
|
|
||||||
|
req = urllib2.urlopen('http://www.imdb.com')
|
||||||
|
res = req.read()
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
def _test_urls(self, urls, handlers, retry=True):
|
def _test_urls(self, urls, handlers, retry=True):
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
|
@ -1166,14 +1166,14 @@ class AbstractHTTPHandler(BaseHandler):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
h.request(req.get_method(), req.get_selector(), req.data, headers)
|
h.request(req.get_method(), req.get_selector(), req.data, headers)
|
||||||
|
except socket.error, err: # XXX what error?
|
||||||
|
h.close()
|
||||||
|
raise URLError(err)
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
r = h.getresponse(buffering=True)
|
r = h.getresponse(buffering=True)
|
||||||
except TypeError: #buffering kw not supported
|
except TypeError: # buffering kw not supported
|
||||||
r = h.getresponse()
|
r = h.getresponse()
|
||||||
except socket.error, err: # XXX what error?
|
|
||||||
raise URLError(err)
|
|
||||||
finally:
|
|
||||||
h.close()
|
|
||||||
|
|
||||||
# Pick apart the HTTPResponse object to get the addinfourl
|
# Pick apart the HTTPResponse object to get the addinfourl
|
||||||
# object initialized properly.
|
# object initialized properly.
|
||||||
|
|
Loading…
Reference in New Issue