I tried to set up a redirection with a custom header to a Netlify function. Here is my netlify.toml conf:
[[redirects]]
from = "/a"
to = "https://other-host.netlify.com/.netlify/functions/slug"
status = 200
force = true
headers = {X-From = "SLUG-A", X-Netlify-Hostname = "a.com"}
[[redirects]]
from = "/b"
to = "https://other-host.netlify.com/.netlify/functions/slug"
status = 200
force = true
headers = {X-From = "SLUG-B", X-Netlify-Hostname = "b.com"}
When running the project with netlify dev, no problem, it’s working. I get the event.headers['x-netlify-hostname’] or the event.headers['x-form’] in my function handler, it’s working perfectly.
But when deployed on Netlify env, these headers are undefined.
Do you have a idea about what could be wrong with my setup ?
Thanks
Could you tell us the actual URL you are testing so we can try to see it in place to advise? There are a few places it could be failing and I’ll need to see your site’s config as a starting place.
Hi @Avri, if you deploy the functions in the same site do you have the same issue? What about if you proxy your actual api or any external api? What i’m wondering is if the issue is specifically because you’re proxying a netlify function.
I tried to proxy to an external service (postb.in). The headers were correctly passed.
I tried to test the project via netlify dev. The headers were correctly passed.
So I think your last sentence is correct: this problem seems to be be specific to netlify functions on live.
Do not hesitates if you need some extra infos.
Thanks,
@Avri, this is a bug. I was able to replicate it. I’ve also gone ahead and filed an issue for our team to look at. We’ll let you know as soon as we have more information. Sorry for the trouble!
To return headers, you do have to code them in your function’s callback or return statement. But for incoming headers as mentioned in the redirect rule, that would be a bug. Since our proxy should be adding those headers to the request so that the function sees it as part of the incoming event.
hi there, some work has happened on this, but as it is connected to some pretty major infra changes relevant for all of the customers on our platform, we’re doing loooots of testing to make sure it all works well at scale. No specific eta yet. We’ll update here with more info once available. thanks for your patience.