summaryrefslogtreecommitdiffstats
path: root/Lib/httplib.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-08-15 22:39:03 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2009-08-15 22:39:03 (GMT)
commit8cabfa352b93e7126d5147a2f8f056cad8d724f6 (patch)
tree61a59f8fda1083c4159f680a46d37839aed9ffb1 /Lib/httplib.py
parent4c6e8088f52c4a1d33ff529685512fd6ebe0d21a (diff)
downloadcpython-8cabfa352b93e7126d5147a2f8f056cad8d724f6.zip
cpython-8cabfa352b93e7126d5147a2f8f056cad8d724f6.tar.gz
cpython-8cabfa352b93e7126d5147a2f8f056cad8d724f6.tar.bz2
Force the http connection to close after any request returned when
buffering=True as our buffered data is not known to the HTTPConnection and may contain data needed by a future request if the connection were left open. See http://bugs.python.org/issue2576 and http://bugs.python.org/issue4879.
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r--Lib/httplib.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 6fc5733..77be68c 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -328,8 +328,12 @@ class HTTPResponse:
def __init__(self, sock, debuglevel=0, strict=0, method=None, buffering=False):
if buffering:
# The caller won't be using any sock.recv() calls, so buffering
- # is fine and recommendef for performance
+ # is fine and recommended for performance.
self.fp = sock.makefile('rb')
+ # As our sock.makefile() object may receive data into its buffer
+ # beyond that needed to satisfy this response, we must close
+ # afterwards.
+ self._must_close = True
else:
# The buffer size is specified as zero, because the headers of
# the response are read with readline(). If the reads were
@@ -337,6 +341,7 @@ class HTTPResponse:
# response, which make be read via a recv() on the underlying
# socket.
self.fp = sock.makefile('rb', 0)
+ self._must_close = False
self.debuglevel = debuglevel
self.strict = strict
self._method = method
@@ -474,6 +479,9 @@ class HTTPResponse:
self.will_close = 1
def _check_close(self):
+ if self._must_close:
+ return True
+
conn = self.msg.getheader('connection')
if self.version == 11:
# An HTTP/1.1 proxy is assumed to stay open unless
@@ -622,6 +630,11 @@ class HTTPResponse:
reading. If the bytes are truly not available (due to EOF), then the
IncompleteRead exception can be used to detect the problem.
"""
+ # NOTE(gps): As of svn r74426 socket._fileobject.read(x) will never
+ # return less than x bytes unless EOF is encountered. It now handles
+ # signal interruptions (socket.error EINTR) internally. This code
+ # never caught that exception anyways. It seems largely pointless.
+ # self.fp.read(amt) will work fine.
s = []
while amt > 0:
chunk = self.fp.read(min(amt, MAXAMOUNT))