The only header path supported is '/*'
Describe the bug
It appears that netlify dev will append response HTTP headers for the /* path only. It will ignore headers for any other paths.
In terms of investigation, I lost several hours trying to apply custom headers for the path: /es, only no matter what I tried it failed. I tried:
- Swapping the order of header declarations
- Both
/esand/es/* - Both
_headersandnetlify.tomlfiles - All combinations of the above
In all cases, only /* was supported for returning headers of any kind, for any path.
Later, I discovered the issues only occurred when running netlify dev locally. When I deploy to netlify the /es/* is honoured and behaves as expected, the different headers for this path are returned in my preview environment.
Steps to reproduce
- Create a
_headersfile. - In the
_headersfile, create some HTTP headers for the path/* - In the
_headersfile now create some HTTP headers for any other path - Run your app locally via
netlify dev - Observe that only the
/*headers are served, the other path headers are never returned.
Configuration
Note this is the _headers file (with other headers removed)
/*
Content-Language: en
/es/*
Content-Language: es
The same issue occurred in my netlify.toml file if I tried it there (deleting _headers first):
# Default headers for all paths
[[headers]]
for = "/*"
[headers.values]
Content-Language = "en"
# Headers specifically for Spanish paths
[[headers]]
for = "/es/*"
[headers.values]
Content-Language = "es"
Environment
System:
OS: macOS 13.3.1
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 299.94 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
npmGlobalPackages:
netlify-cli: 16.9.2