我的app.yaml
中有以下处理程序部分:
handlers:
- url: /(robots\.txt|sitemap\.xml)
static_files: \1
upload: (robots\.txt|sitemap\.xml)
secure: always
http_headers:
Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
- url: /.*
script: main.app
secure: always
http_headers:
Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
由另一个子模块(
static.yaml
)提供服务的另一个子域具有以下内容:handlers:
- url: /
static_dir: files
secure: always
http_headers:
Access-Control-Allow-Origin: '*'
Strict-Transport-Security: 'max-age=63072000; preload'
我能够毫无问题地将
static.yaml
部署到appengine:$ appcfg.py update static.yaml
12:48 PM Host: appengine.google.com
12:48 PM Application: XXXXXX; module: static; version: 1
12:48 PM
Starting update of app: XXXXXXXX, module: static, version: 1
12:48 PM Getting current resource limits.
12:48 PM Scanning files on local disk.
[...]
[...]
12:49 PM Checking if updated app version is serving.
12:49 PM Completed update of app: XXXXXX, module: static, version: 1
而当我尝试更新
app.yaml
配置时,我得到:$ appcfg.py update app.yaml
12:48 PM Host: appengine.google.com
Usage: appcfg.py [options] update <directory> | [file, ...]
appcfg.py: error: Error parsing .\app.yaml: Unexpected attribute "http_headers" for mapping type script.
in ".\app.yaml", line 31, column 1.
我知道这意味着我必须在自己的python脚本中处理HSTS配置。但是,我在
main.app
接口中有大约10个处理程序。除了更新每个参数以添加STS标头之外,还有其他替代方法可以在app.yaml
级别上使用吗?检查
app.yaml
reference on GAE时,在http_header
类型映射中没有提及对script
指令的限制。 最佳答案
您可以使用app.yaml为静态文件处理程序而非动态处理程序控制HTTP headers。您需要在应用程序代码中设置标题。