为什么GAE dev_appserver只设置ETag,而不是Expires HTTP头?

时间:2013-05-06 18:06:41

标签: google-app-engine app.yaml dev-appserver dev-appserver-2

档案&文件夹结构

我有以下目录结构。

[app_root]
|
|---[static]
    |
    |--- [css]
    |--- [img]
    |--- [js]
         |--- [app]
         |--- [libs]
         |--- main.js
         |--- require.js

的app.yaml

app.yaml处理程序的static_dir配置设置为不同的到期时间。

application: my-app-name
version: 1
runtime: python27
api_version: 1
threadsafe: true

default_expiration: "10d"

handlers:
- url: /favicon\.ico
  static_files: static/img/favicon.ico
  upload: static/img/favicon\.ico
  expiration: "364d"

- url: /static/img
  static_dir: static/img
  expiration: "364d"
  http_headers:
    X-Static-Img: Moo1

- url: /static/css
  static_dir: static/css
  expiration: "15m"
  http_headers:
    X-Static-Css: Moo2

- url: /static/js/app
  static_dir: static/js/app
  expiration: "15m"
  http_headers:
    X-Static-Js-App: Moo4

- url: /static/js/libs
  static_dir: static/js/libs
  expiration: "7d"
  http_headers:
    X-Static-Js-Libs: Moo5

- url: /static/js
  static_dir: static/js
  expiration: "15m"
  http_headers:
    X-Static-Js-Root: Moo3

- url: /static
  static_dir: static
  expiration: 12d
  http_headers:
    X-Static-ROOT: MOOOOOOOOOOO COW

HTTP标头

/ static / css - 第一次

Request URL:http://localhost:8080/static/css/bootstrap.min.css
Request Method:GET
Status Code:200 OK

======================
   Request Headers
======================
Accept:text/css,*/*;q=0.1
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:dev_appserver_login="test@admin.com:True:113617613220115205203"
DNT:1
Host:localhost:8080
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31

======================
   Response Headers
======================
Cache-Control:no-cache
Content-length:103314
Content-type:text/css
Date:Mon, 06 May 2013 17:46:22 GMT
ETag:"MTgwMTU4MDk3NA=="
Expires:Fri, 01 Jan 1990 00:00:00 GMT
Server:Development/2.0
X-Static-Css:Moo2

/ static / css - 后续请求

Request URL:http://localhost:8080/static/css/bootstrap.min.css
Request Method:GET
Status Code:304 Not Modified

======================
   Request Headers
======================
Accept:text/css,*/*;q=0.1
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:dev_appserver_login="test@admin.com:True:113617613220115205203"
DNT:1
Host:localhost:8080
If-None-Match:"MTgwMTU4MDk3NA=="
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31

======================
   Response Headers
======================
Date:Mon, 06 May 2013 17:53:20 GMT
ETag:"MTgwMTU4MDk3NA=="
Server:Development/2.0

问题

在初始请求时,Expires标头过去设置为Fri, 01 Jan 1990 00:00:00 GMT 我认为至少应根据"15m"将其设置为app.yaml

但所有后续请求仅使用ETag获取HTTP 304 Not Modified Expires标题完全丢失。

我做错了吗?

谢谢,

1 个答案:

答案 0 :(得分:2)

dev_appserver2有问题。我看到的和你一样。

当我使用旧的dev_appserver时,我的第一个请求正在使用正确的expires标头,但我没有设置任何额外的标头。

虽然我没有看到304回复过期,但看起来很好。

旧的dev_appserver更接近生产行为,但生成的标题仍然存在一些细微差别。