当 firebase.json 有两组(或更多)适用于特定路径的 "headers" 规则时,Firebase Hosting 的行为如何?

How does Firebase Hosting behaves when firebase.json has two (or more) sets of "headers" rules that apply to a specific path?

如果您在 Firebase 托管 firebase.json 文件上设置 2 headers 规则作为通用规则和更具体的规则,以某种方式某些路径会匹配这两个规则,Firebase 如何托管在那种情况下表现如何?它是否按数组顺序覆盖和合并 header 值?

例如:

firebase.json

"headers": [
  {
    "source": "/**",
    "headers": [
      { "key": "Cache-Control", "value": "max-age=3600" },
      { "key": "Vary",          "value": "User-Agent" }
    ]
  },
  {
    "source": "/api/**",
    "headers": [
      { "key": "Cache-Control",               "value": "no-cache" },
      { "key": "Access-Control-Allow-Origin", "value": "https://www.example.com" }
    ]    
  }
]

我可以假设 /api/** 调用会按顺序从两组 header 规则中获得 覆盖/合并结果吗? 我的意思是,这里的顺序很重要,对吧?

/api 的结果将是:

Cache-Control: no-cache
Vary: User-Agent
Access-Control-Allow-Origin: https://www.example.com

我刚刚进行了测试,结果如下:

它将按照 headers 出现的顺序覆盖并合并它们。

例如:

"headers": [
  {
    "source": "/**",
    "headers": [
      { "key": "Cache-Control", "value": "max-age=3600" },
      { "key": "Vary",          "value": "User-Agent" }
    ]
  },
  {
    "source": "/api/**",
    "headers": [
      { "key": "Cache-Control",               "value": "no-cache" },
      { "key": "Access-Control-Allow-Origin", "value": "https://www.example.com" }
    ]    
  }
]

根据上面的代码,对于 /api/something 调用,它将 return 以下内容:

Cache-Control: no-cache
Vary: User-Agent
Acess-Control-Allow-Origin: https://www.example.com