From: Senthil Kumaran Date: Sun, 29 Apr 2012 02:40:23 +0000 (+0800) Subject: httplib - minor update to check empty response X-Git-Tag: v3.3.0a3~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=150c36543065821f8dc12af4eca200b6a414bb8c;p=thirdparty%2FPython%2Fcpython.git httplib - minor update to check empty response --- 150c36543065821f8dc12af4eca200b6a414bb8c diff --cc Lib/http/client.py index eb857c03ca72,d226f63ac4ad..9c110d5a0458 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@@ -523,44 -506,14 +523,44 @@@ class HTTPResponse(io.RawIOBase) # we do not use _safe_read() here because this may be a .will_close # connection, and the user is reading more bytes than will be provided # (for example, reading in 1k chunks) - s = self.fp.read(amt) + n = self.fp.readinto(b) if self.length is not None: - self.length -= len(s) + self.length -= n if not self.length: self.close() - return s + return n + + def _read_next_chunk_size(self): + # Read the next chunk size from the file + line = self.fp.readline(_MAXLINE + 1) + if len(line) > _MAXLINE: + raise LineTooLong("chunk size") + i = line.find(b";") + if i >= 0: + line = line[:i] # strip chunk-extensions + try: + return int(line, 16) + except ValueError: + # close the connection as protocol synchronisation is + # probably lost + self.close() + raise - def _read_chunked(self, amt): + def _read_and_discard_trailer(self): + # read and discard trailer up to the CRLF terminator + ### note: we shouldn't have any trailers! + while True: + line = self.fp.readline(_MAXLINE + 1) + if len(line) > _MAXLINE: + raise LineTooLong("trailer line") + if not line: + # a vanishingly small number of sites EOF without + # sending the trailer + break - if line == b"\r\n": ++ if line in (b'\r\n', b'\n', b''): + break + + def _readall_chunked(self): assert self.chunked != _UNKNOWN chunk_left = self.chunk_left value = []