Get custom header on proxying request to Netlify function

Hi !
Following this thread:

I tried to set up a redirection with a custom header to a Netlify function. Here is my netlify.toml conf:

  from = "/a"
  to = ""
  status = 200
  force = true
  headers = {X-From = "SLUG-A", X-Netlify-Hostname = ""}

  from = "/b"
  to = ""
  status = 200
  force = true
  headers = {X-From = "SLUG-B", X-Netlify-Hostname = ""}

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 ?

Sorry it’s taken me so long to respond!

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! No problem for the delay :slight_smile:
So, here are my repos and netlify links:

This project contains the Netlify function called via a Proxy redirect.


Project which contains the Proxy Redirect. There are 4 links:

  • /a => should be a proxy to a Netlify function with a specific header
  • /b => should be a proxy to a Netlify function with another header
  • /c & /d => some tests with a link middleware


Some precisions:
when clicking on a link on this site:, some timeouts are occurring (but sometimes it works correctly).

When running this site with netlify dev, everything is working fine :thinking:

An other precision:
when using an other service for the proxy redirect, eg. with a PostBin call with the following call:

  from = "/a"
  to = ""
  status = 200
  force = true
  headers = {X-From = "SLUG-A", X-Netlify-Hostname = ""}

Headers transmission is working fine. So maybe there is a problem with Functions, like there are not receiving headers correctly ?

There are only two redirects on that site, none of which you’re talking about, and none of which have any headers included:

"path"=>"/test1", "to"=>"/.netlify/functions/slug", "status"=>200, "force"=>true
"path"=>"/test2", "to"=>"/.netlify/functions/slug", "status"=>200, "force"=>true

So - I think the problem is in deploying the redirects and not in using them :slight_smile:

Those do match what you have in your toml file though: - so I think it isn’t a deployment problem either. I’m a bit confused about how you are expecting /a and /b etc to work.

I’ve done some cleanup to clarify things. In fact, as said in my previous message there are two repos:

1- one containing the function:
Here is the link to the function:

2- one containing the redirects:
Here is the link:

So, you’ll find here the redirects for /a and /b:

Hi, any news on this problem ?

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.

Hi @futuregerald, sorry for the delay.
I updated one project to use functions in the same project than the redirect, as you can see here:

Same problem, all headers are undefined:

Some investigations:

  • I tried to proxy to an external service ( 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.

@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!

1 Like

No problem, thanks!
Happy to contribute, let me know when you’ll have more infos.

1 Like

Actually, not confident this is a bug – see here: _headers / .toml / CORS

For functions, I think what’s in toml files is fully ignored – you have to code them in the function callback.

As link says.

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.

Good point though.

Sounds right, and thanks for taking the close look, Dennis – presume this will find its way into a release.


Yea, we do have an issue around that and will update here if and when we get things fixed up.


Having the same issue here. No luck with JSON web signatures either. I assume it’s related to the same bug. Any news?

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.