Issue1065257
Created on 2004年11月12日 15:48 by alien_life_form, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files |
| File name |
Uploaded |
Description |
Edit |
|
httplib2.patch
|
alien_life_form,
2004年11月12日 15:48
|
httplib: allowing stream-type body part in requests |
| Messages (2) |
|
msg47287 - (view) |
Author: Alessandro Forghieri (alien_life_form) |
Date: 2004年11月12日 15:48 |
Greetings.
The attached patch makes it possible to use a file-like
object in httplib requests (useful to PUT large files
without exhausting the machine memory - think a DAV
server).
The supplied object must be able to read().
If Content-Length support is desired, the body object
must either have a __length__ method (so len(body)
works) OR have a stat-able "name" property (file
objects are in the second category).
Having applied this patch the following works:
import httplib
import base64
hh={}
auth = base64.encodestring("%s:%s" %
("guest","guest")).rstrip()
hh['Authorization']='Basic %s' % auth
conn=HTTPConnection('localhost',8080)
conn.debuglevel=99
thestream=open(r'\tmp\huge.pdf','rb')
conn.request('PUT',
'/dav/streamed',
thestream,hh)
thestream.close()
rsp=conn.getresponse()
print
rsp.status,"-",rsp.reason,repr(rsp.msg.dict),rsp.read()
conn.close()
Opening in 'rb' mode - on windoze - is important for
this to work, or the content length header will be
wrong, which is probably BAD.
Alessandro Forghieri
|
|
msg47288 - (view) |
Author: Martin v. Löwis (loewis) * (Python committer) |
Date: 2006年11月12日 10:33 |
Logged In: YES
user_id=21627
Thanks for the patch. Committed (with modifications) as r52736.
|
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2022年04月11日 14:56:08 | admin | set | github: 41165 |
| 2004年11月12日 15:48:57 | alien_life_form | create |