Per the Serverless Function Headers documentation, the following headers provided in lowercase to serverless functions:
- accept
- accept-encoding
- accept-language
- cache-control
- connection
- cookie
- host
- true-client-ip
- upgrade-insecure-requests
- user-agent
- x-forwarded-for
However, I tested using `console.log(context.headers)` many (but not all) of the headers are using Title-Case:
2023-05-17T14:49:21.995Zing INFO {
'true-client-ip': '2603:...',
'User-Agent': 'curl/8.0.1',
'Accept-Encoding': 'gzip',
Accept: '*/*',
'X-IP-Country': 'US',
Connection: 'close',
Host: '...',
'X-Forwarded-For': '2603:..., 162.158.79.216,172.16.46.60, 2603:...'
}
This particular request was made with curl, but the headers for a request from Chrome also appear to be title case as well.
Can someone please confirm the header names are expected to be Title-Case as I’m seeing, and then update the reference documentation to reflect that?
Hey, @eterobby
Thanks for taking the time to point this out. It helps all of us and is appreciated.
Based on my understanding of HTTP headers, the case should technically not matter. And consistency in the documentation is important.
I’m going to reach out to our documentation team to confirm whether the headers should be in title case or not, and make sure the reference documentation is updated accordingly.
I’ll update here if I get any additional updates to share. — Jaycee
Correct, header names are supposed to be case-insensitive, but keys in JavaScript objects are case-sensitive so that’s where the challenge arises.
In my testing, context.headers.host was undefined while context.headers.Host contained the host name value, regardless of the case used by the HTTP client I used.
If you pass a simple JS object, then you either must use a particular case for each header, or you could duplicate the same header with multiple keys using different case variants. In my experience, Node.JS typically lowercases all header names, although that behavior is inconsistent with your current behavior. You could probably use a JS Proxy to support functions checking with any header case.
I suspect the current behavior is simply an artifact of the systems you use to power the HubSpot CMS and server less functions.