Cannot add response header to external redirect

I’ve been trying to use the newish redirect syntax to add CORS headers to a proxy response from the Wikimedia API. I’ve tried this:

[[redirects]]

from = "/wikimedia/*"
to = "https://en.wikipedia.org/w/api.php:splat"
status = 200
force = false

[[headers]]
for = "/wikimedia/*"
[headers.values]
Access-Control-Allow-Origin = "*"
X-From = "netlify"

And it does proxy correctly, but no headers get added.

Note that I also send CORS headers for the entire website anyway:

[[headers]]

for = "/*"
[headers.values]
Access-Control-Allow-Origin = "*"

which work fine for other responses. However, when proxying, none of the headers I try to add seem to get added. Any ideas?

Hi @LeaVerou,

The syntax is explained here:

It should be:

[[redirects]]
  from = "/wikimedia/*"
  to = "https://en.wikipedia.org/w/api.php:splat"
  status = 200
  force = false
  headers = {X-From = "Netlify"}

I generally do RTFM extensively before asking a question in forums :slight_smile: In this case, I’ve already gone through the document you linked to multiple times, and the syntax you provide is the very first one I tried, way before posting here.
It didn’t work, and after some digging in the forums, it turned out that those are the headers that Netlify sends to the service you are proxying, not response headers for the actual end response that is sent to the visitor’s browser.
This is the post that led me to the syntax I posted (which also didn’t work): Netlify does not send custom headers in a redirect file (using https in the "to") - #15 by luke

(thanks for the fast response tho!)

Hey there, @LeaVerou

Can you share your site name and your repo with us? This will help us look into your issue further. Thanks!