簡體   English   中英

Google App Engine添加緩存控制和其他標頭

[英]Google App Engine adding cache-control and other headers

我在Google App Engine上有一個Flask應用程序,我想告訴瀏覽器緩存使用Cache-Control標頭的響應。 它可以在dev_appserver.py上按預期工作,但是在部署到App Engine時,標頭會被修改並破壞緩存標頭。

特別是以下Flask視圖:

@app.route("/resource")
def resource():
    response = make_response(render_template("resource.html"))
    response.headers['Cache-Control'] = "max-age=31536000"
    logging.error("HEADERS: {}".format(response.headers))
    return response

開發服務器和App Engine的日志均顯示:

Content-Type: text/html; charset=utf-8
Content-Length: 112628
Cache-Control: max-age=31536000

當我在開發應用服務器上運行它時,它可以按預期工作,如下面的標題所示。

當我打開Chrome的開發工具時,App Engine的標題為:

alternate-protocol:443:quic
cache-control:no-cache, must-revalidate
content-encoding:gzip
content-length:19520
content-type:text/html; charset=utf-8
date:Wed, 22 Jan 2014 19:53:47 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:Google Frontend
set-cookie:session=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
status:200 OK
strict-transport-security:max-age=31536000
vary:Accept-Encoding
version:HTTP/1.1
x-appengine-estimated-cpm-us-dollars:$0.002267
x-appengine-resource-usage:ms=7388 cpu_ms=5069
x-frame-options:DENY
x-ua-compatible:chrome=1

相反,開發應用程序服務器標頭與預期的一樣:

Cache-Control:max-age=31536000, private
Content-Length:112628
content-type:text/html; charset=utf-8
Date:Wed, 22 Jan 2014 19:57:05 GMT
Expires:Wed, 22 Jan 2014 19:57:05 GMT
Server:Development/2.0
set-cookie:session=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
x-frame-options:DENY
x-ua-compatible:chrome=1

當然,我已經進行檢查以確保沒有添加額外的頭,並且找不到給定視圖之外添加的與cache-control相關的頭( pragmaexpirescache-control )的引用。

因此,似乎App Engine在部署時會添加一堆標題,這似乎很不正常。 我可能忽略了什么?

-編輯-

正如@dinoboff 在下面的評論中從文檔中指出的

緩存控制,過期和變化

這些標頭為中間Web代理(例如Internet服務提供商)和瀏覽器指定緩存策略。 如果您的腳本設置了這些標頭,那么除非響應包含Set-Cookie標頭,或為使用管理員帳戶登錄的用戶生成的響應否則它們通常不會被修改。

這些標頭是添加的其他標頭,因為您正在以登錄的管理員用戶身份查看站點。 對於“普通”用戶,它們將不存在。

這篇博客文章專門討論了X-AppEngine-Resource-Usage標頭: http : //googleappengine.blogspot.co.uk/2009/08/new-features-in-124.html

正如他們所指出的:

您可以使用Firefox的Live HTTP標頭或Firebug等插件查看這些標頭。 請注意,只有已登錄的管理員才能看到這些數字-普通用戶和未登錄的用戶將根本看不到它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM