pwsm / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Sending a file object as the body in a request can cause infinite wait #176

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I've been writing a webdav client library, using httplib2, on and off for some 
time. An issue that I came across was attempting to send large files without 
reading them into memory first. I found that httplib itself will accept an open 
file and read blocks of the file without reading the whole thing into memory. 
Since httplib2 uses httplib for the sending of the requests, this solution 
would work ok.

However, when sending to a host that requires authentication, using an open 
file causes an issue. The file is read and sent during the first request (when 
no credentials have been sent along in the request). Then the server gives a 
401 response and the request is sent again, this time with the credentials in 
the headers. Unfortunately, the open file now has the file pointer at the end 
of the file and the server now sits and waits for data that will never come 
(because there is no more file to send).

I have created a little work around and attached a diff of the __init__.py file 
containing the changes but have not yet created any tests as I don't even know 
if you'd be interested in it.

Also, this is for the python2 __init__.py file only as again, I wanted to gauge 
interest before proceeding.

The change itself just detects whether or not the body argument is a file type 
object and if so, records where the file pointer starts and resets it to the 
same point if a 401 response is given by the server.

Original issue reported on code.google.com by bex.le...@gmail.com on 21 Sep 2011 at 11:39

Attachments: