如何解决Google Storage HEAD 响应缺少内容长度
我正在使用一个库 (Apache Libcloud) 向谷歌存储发出请求。
在库内部,向在谷歌存储中查询的 URL 发出 HEAD 请求。
您可以找到它的代码 here,搜索 def get_object
。
重要的一行是
response = self.connection.request(object_path,method='HEAD')
根据 Google Documentation of HEAD response objects,content-length
字段应该是响应的一部分:
Response
...
expires: Wed,30 May 2018 21:41:23 GMT
date: Wed,30 May 2018 21:41:23 GMT
cache-control: private,max-age=0
last-modified: Wed,30 May 2018 20:36:34 GMT
etag: "2218880ef78838266ecd7d4c1b742a0e"
x-goog-generation: 1486161811706000
x-goog-metageneration: 15
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 328
content-type: image/jpg
x-goog-hash: crc32c=HBrbzQ==
x-goog-hash: md5=OCydg52+pPG1Bwawjsl7DA==
x-goog-storage-class: STANDARD
accept-ranges: bytes
content-length: 328 # <--- here
...
但是,某些文件(但并非所有文件)缺少它。
在这两种情况下,我都收到了 x-goog-stored-content-length
条目,但图书馆需要 content-length
。
content-length
标头在 def _headers_to_object
中的调用链下游使用了一点,由于缺少标头,我在那里得到了 KeyError:
def _headers_to_object(self,object_name,container,headers):
hash = headers['etag'].replace('"','')
extra = {'content_type': headers['content-type'],'etag': headers['etag']}
meta_data = {}
if 'last-modified' in headers:
extra['last_modified'] = headers['last-modified']
for key,value in headers.items():
if not key.lower().startswith(self.http_vendor_prefix + '-meta-'):
continue
key = key.replace(self.http_vendor_prefix + '-meta-','')
meta_data[key] = value
obj = Object(name=object_name,size=headers['content-length'],# <-- here
hash=hash,extra=extra,meta_data=meta_data,container=container,driver=self)
return obj
问题是: 当我上传文件导致谷歌存储不发送该标头时,我可能对文件做了什么? 或者这是谷歌存储中的错误(我怀疑)?
更多信息:
- 内容类型为
application/json
- 此文件采用 gzip 编码。
- 它适用于其他 gzip 编码文件
- 我使用的是 Apache Libcloud API 3.3.0
- 我不认为这是 libcloud 中的错误,因为 HEAD 的文档指定了
content-length
标头,但如果我覆盖_headers_to_object
以使用x-goog-stored-content-length
,它会起作用。 - 我无法使用我目前可以公开演示的文件来重现这一点
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。