]> granicus.if.org Git - python/commitdiff
httplib - minor update to check empty response
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 29 Apr 2012 02:40:23 +0000 (10:40 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 29 Apr 2012 02:40:23 +0000 (10:40 +0800)
1  2 
Lib/http/client.py

index eb857c03ca720895c8d20a66d3bff133c2bb90b4,d226f63ac4ad52f40d59aa3af66690889e1d0e1f..9c110d5a04586f807b10159c106eb8a4a0f77f16
@@@ -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 = []