cli icon indicating copy to clipboard operation
cli copied to clipboard

The only header path supported is '/*'

Open yoniholmes opened this issue 2 years ago • 0 comments

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:

  1. Swapping the order of header declarations
  2. Both /es and /es/*
  3. Both _headers and netlify.toml files
  4. 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

  1. Create a _headers file.
  2. In the _headers file, create some HTTP headers for the path /*
  3. In the _headers file now create some HTTP headers for any other path
  4. Run your app locally via netlify dev
  5. 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

yoniholmes avatar Oct 26 '23 21:10 yoniholmes