[ python-Bugs-988120 ] httplib.HTTPResponse.read() not updating the length correctl

SourceForge.net noreply at sourceforge.net
Sat Jul 10 05:31:11 CEST 2004


Bugs item #988120, was opened at 2004-07-09 13:37
Message generated for change (Comment added) made by gvanrossum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=988120&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Mihai Ibanescu (misa)
Assigned to: Nobody/Anonymous (nobody)
Summary: httplib.HTTPResponse.read() not updating the length correctl

Initial Comment:
I believe there is a bug in HTTPResponse.read. This is
the last part:
                                                      
                         
                                                      
                         
                                                      
                         
        if self.length is not None:
            if amt > self.length:
                # clip the read to the "end of response"
                amt = self.length
            self.length -= amt
                                                      
                         
        # 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)
                                                      
                         
        return s
                                                      
                         
                                                      
                         
self.length is the response's length as presented by
the Content-Length header.
                                                      
                         
If I am not mistaken, self.fp.read(amt) (for the case
where amt is not None) returns _up to_, not _exactly_
amt bytes.
                                                      
                         
So, if amt is originally 1024 bytes and self.fp.read
returns only 520 bytes (because, let's say, you are
reading from an SSL socket), then self.length is
decremented by 1024 and not by 520. So you end up
reading less than self.length
                                                      
                         
I am seeing this when plugging an SSL socket/file from
pyOpenSSL.


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2004-07-09 23:31

Message:
Logged In: YES 
user_id=6380

Python's regular files always return the requested amount
except at EOF. But many file-like objects don't guarantee
this, so I agree that it's better to only adjust the
position by the number of bytes actually read.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=988120&group_id=5470


More information about the Python-bugs-list mailing list