Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e11b3f

Browse files
author
Kristján Valur Jónsson
committed
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
1 parent bc186a8 commit 7e11b3f

2 files changed

Lines changed: 7 additions & 24 deletions

File tree

Lib/http/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ class HTTPResponse:
265265
# accepts iso-8859-1.
266266

267267
def __init__(self, sock, debuglevel=0, strict=0, method=None):
268-
# XXX If the response includes a content-length header, we
268+
# If the response includes a content-length header, we
269269
# need to make sure that the client doesn't read more than the
270270
# specified number of bytes. If it does, it will block until
271271
# the server times out and closes the connection. (The only
272-
# applies to HTTP/1.1 connections.) Since some clients access
273-
# self.fp directly rather than calling read(), this is a little
274-
# tricky.
275-
self.fp = sock.makefile("rb", 0)
272+
# applies to HTTP/1.1 connections.) This will happen if a self.fp.read()
273+
# is done (without a size) whether self.fp is buffered or not.
274+
# So, no self.fp.read() by clients unless they know what they are doing.
275+
self.fp = sock.makefile("rb")
276276
self.debuglevel = debuglevel
277277
self.strict = strict
278278
self._method = method

Lib/xmlrpc/client.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ def request(self, host, handler, request_body, verbose=0):
11291129

11301130
self.verbose = verbose
11311131

1132-
return self._parse_response(resp, None)
1132+
return self.parse_response(resp)
11331133

11341134
##
11351135
# Create parser.
@@ -1212,29 +1212,12 @@ def send_request(self, host, handler, request_body, debug):
12121212
# @return Response tuple and target method.
12131213

12141214
def parse_response(self, file):
1215-
# compatibility interface
1216-
return self._parse_response(file, None)
1217-
1218-
##
1219-
# Parse response (alternate interface). This is similar to the
1220-
# parse_response method, but also provides direct access to the
1221-
# underlying socket object (where available).
1222-
#
1223-
# @param file Stream.
1224-
# @param sock Socket handle (or None, if the socket object
1225-
# could not be accessed).
1226-
# @return Response tuple and target method.
1227-
1228-
def _parse_response(self, file, sock):
12291215
# read response from input file/socket, and parse it
12301216

12311217
p, u = self.getparser()
12321218

12331219
while 1:
1234-
if sock:
1235-
response = sock.recv(1024)
1236-
else:
1237-
response = file.read(1024)
1220+
response = file.read(1024)
12381221
if not response:
12391222
break
12401223
if self.verbose:

0 commit comments

Comments
 (0)