[PATCH] Bucket.get_key(): handle missing content-length

114 views
Skip to first unread message

Colin Patrick McCabe

unread,
Mar 17, 2011, 7:46:19 PM3/17/11
to Mitch Garnaat, boto...@googlegroups.com, Sage Weil, Yehuda Sadeh, Colin Patrick McCabe, Colin McCabe
Hi all. I am working on an S3-compatible object store called RGW (Rados
Gateway).

More information about RGW is available here:
http://ceph.newdream.net/wiki/RADOS_Gateway

We are using Apache with fastcgi to serve our HTTP requests. Unfortunately,
Apache omits content-length on HTTP HEAD responses when content-length is 0.
This patch allows libboto to handle this gracefully.

For more details about Apache and Content-Length, see:
http://perl.apache.org/docs/2.0/user/handlers/http.html#C_Content_Length__Response_Header

Signed-off-by: Colin McCabe <colin....@dreamhost.com>
---
boto/s3/bucket.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/boto/s3/bucket.py b/boto/s3/bucket.py
index d56e4cc..0abff64 100644
--- a/boto/s3/bucket.py
+++ b/boto/s3/bucket.py
@@ -175,7 +175,11 @@ class Bucket(object):
k.content_type = response.getheader('content-type')
k.content_encoding = response.getheader('content-encoding')
k.last_modified = response.getheader('last-modified')
- k.size = int(response.getheader('content-length'))
+ clen = response.getheader('content-length')
+ if (clen):
+ k.size = int(clen)
+ else:
+ k.size = 0
k.cache_control = response.getheader('cache-control')
k.name = key_name
k.handle_version_headers(response)
--
1.7.2.3

Mitchell Garnaat

unread,
Mar 18, 2011, 5:01:29 PM3/18/11
to Colin Patrick McCabe, boto...@googlegroups.com, Sage Weil, Yehuda Sadeh, Colin McCabe
That looks like a reasonable patch.  I'll integrate it locally and run the existing S3 tests.  If there are no issues, you should see it appear on github very soon.

Thanks for the patch,

Mitch

Colin McCabe

unread,
Mar 18, 2011, 8:32:04 PM3/18/11
to Mitchell Garnaat, boto...@googlegroups.com, Sage Weil, Yehuda Sadeh
Thanks Mitchell!

Colin

Mitchell Garnaat

unread,
Mar 19, 2011, 8:32:53 AM3/19/11
to Colin McCabe, boto...@googlegroups.com, Sage Weil, Yehuda Sadeh
Reply all
Reply to author
Forward
0 new messages