简体   繁体   English

Google App Engine提供Content-Length标头

[英]Google App Engine serve Content-Length header

I'm using the following to serve a file from GS through PHP App Engine: 我正在使用以下内容通过PHP App Engine从GS提供文件:

google\appengine\api\cloud_storage\CloudStorageTools::serve

This doesn't set the Content-Length header and App Engine doesn't allow that header to be set manually by a script. 这不会设置Content-Length标头,App Engine也不允许脚本手动设置该标头。 ( https://cloud.google.com/appengine/docs/python/how-requests-are-handled#headers_removed ) https://cloud.google.com/appengine/docs/python/how-requests-are-handled#headers_removed

How can I set the Content-Length header so the user has an idea of how large the file is when they start to download it? 如何设置Content-Length标头,以便用户知道文件开始下载时的大小?

I have experience with App Engine but used with Python, but I hope this is useful. 我有App Engine的经验但是和Python一起使用,但我希望这很有用。

App Engine will remove the Content-Length header if you set it manually, but it will automatically set it before the response is sent to the client. 如果手动设置,App Engine将删除Content-Length标头,但会在将响应发送到客户端之前自动设置它。

This ensures there are no mistakes on the value and it will be the length of the absolute final response sent by App Engine. 这确保了值上没有错误,它将是App Engine发送的绝对最终响应的长度。

I have tested this with a new simple app by setting a wrong size manually, leaving it blank and setting the correct size. 我通过手动设置错误的大小,将其留空并设置正确的大小,使用新的简单应用程序对此进行了测试。 In all three tests, the correct Content-Length is returned to the client by App Engine. 在所有三个测试中,App Engine将正确的Content-Length返回给客户端。

Have you tested from the client to see if the header is present and correct? 您是否已从客户端进行测试以查看标头是否存在且是否正确?

I hope this helps clarify that while App Engine will remove the header if you set it, it will set it to the correct value automatically. 我希望这有助于澄清,如果您设置它,App Engine将删除标题,它会自动将其设置为正确的值。

If you use the script provided by google gsutil and run " du " command you should be able to get that data. 如果您使用google gsutil提供的脚本并运行“ du ”命令,您应该能够获取该数据。 Also you have some interesting examples of the API's functionality here and how install gsutil here . 此外,您还可以在此处获得有关API功能的一些有趣示例以及如何在此处安装gsutil。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM