diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2009-02-02 16:04:04 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2009-02-02 16:04:04 (GMT) |
commit | 7e11b3f52247f0a0fd8be8879873a74d4ec02b38 (patch) | |
tree | 578dba804293c292fb033364d9df748f5101f612 /Lib/http | |
parent | bc186a87ccd09a62339492cfca794841cab07087 (diff) | |
download | cpython-7e11b3f52247f0a0fd8be8879873a74d4ec02b38.zip cpython-7e11b3f52247f0a0fd8be8879873a74d4ec02b38.tar.gz cpython-7e11b3f52247f0a0fd8be8879873a74d4ec02b38.tar.bz2 |
merging / reimplementing r68532 from the trunk to Py3k
Enable buffering for HTTPResponse's fp. read() behaves identically for buffered and non-buffered IO. read(n) also won't block if n bytes are availble on the socket. There is therefore no reason not to use buffering. The reason 2.x disables buffering by default, that some clients may be accessing the underlying socket directly and so bypass the buffering buffer, doesn't apply in 3.x with its redesigned IO library.
See issue 4448 and issue 4879
Diffstat (limited to 'Lib/http')
-rw-r--r-- | Lib/http/client.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index d2900b1..f816d58 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -265,14 +265,14 @@ class HTTPResponse: # accepts iso-8859-1. def __init__(self, sock, debuglevel=0, strict=0, method=None): - # XXX If the response includes a content-length header, we + # If the response includes a content-length header, we # need to make sure that the client doesn't read more than the # specified number of bytes. If it does, it will block until # the server times out and closes the connection. (The only - # applies to HTTP/1.1 connections.) Since some clients access - # self.fp directly rather than calling read(), this is a little - # tricky. - self.fp = sock.makefile("rb", 0) + # applies to HTTP/1.1 connections.) This will happen if a self.fp.read() + # is done (without a size) whether self.fp is buffered or not. + # So, no self.fp.read() by clients unless they know what they are doing. + self.fp = sock.makefile("rb") self.debuglevel = debuglevel self.strict = strict self._method = method |