I am working with github hooks and headers and noticed issue:
It transforms some parts of header: X-GitHub-Event -> X-Github-Event. GitHub -> Github.
Hub-Eventhub-EventIt fixes in my app as:
const githubEvent = event.headers['X-GitHub-Event'] || event.headers['X-Github-Event'];
I also meet this issues, not matter I put lang or Lang I will get Lang when offline. But when I deploy in the aws , it is not.
Can you guys fix it please ? Thanks. There's a header processing step somewhere in the code. It capitalises headers. At the time it was relevant, but AWS changed (again) since.
I got it,
In the HTTP protocol definition, headers are case-insensitive so Hapi (our http framework) lowercases them.
A contributor fixed it by capitalizing them again. but capital characters in the middle of are word cannot be recovered.
I believe there is a way to access Hapi's raw headers.
I think I fixed it in v3.15.3, can you guys confirm ?
Is it possible that a similar issue exists for response headers?
I have a response with multiple 'set-cookie' headers, each with different casing (as done by serverless-http).
In debug I can follow up to "Bon voyage" - response.send() and at that point I still see 6 cookies. The response coming back to my client though only contains the last header ("SeT-cookie" in my case, so it's not that only the lower-case variant remains).
I tried following through Hapi code but I can't spot the problem.
For the record: on AWS it works fine, and I used v3.15.3
Think I found it: it's interference between serverless-http and Hapi:
serverless-http takes a single 'set-cookie' header with an array value (in my case produced by express) and transforms those into separate 'set-cookie', 'Set-cookie',... headers.
Hapi expects to find a single set-cookie header with (possibly) an array value.
So no issue with serverless-offline - sorry!
Can confirm this caused a bug for me. I was expecting lowercase headers using AWS. AWS sends them as they come in. I have fixed it in my handler:
const headers = Object.keys(event.headers)
for (const key in headers) {
event.headers[key.toLowerCase()] = event.headers[key]
}
To replicate AWS even more the headers case shouldn't be touched.
I sent Authorization header to the lambda and the header i receive is with first letter lowercase authorization. When i upload the lambda in the cloud it works fine. The problem only exist when i serve the lambda locally
Something akin to what @FreeWillaert said is breaking using this with aws-serverless-express and cookie-session
Long story short somewhere between aws-serverless-express and serveless-offline something only respects the last header that is set
By default cookie-session is designed to sign cookies....
Which sets 2 header values
1 for the actual session and a second for the signature of that session.. which is a second and in my case final call to set cookie.
Which blows away the value we actually wanted to set as a cookie.
o.o
Found this after about 16 straight hours of googling and debugging.
@dherault why was this closed?
I think the initial issue is solved. The headers X-GitHub-Event stays unchanged now in version 3.24.3.
Most helpful comment
I sent
Authorizationheader to the lambda and the header i receive is with first letter lowercaseauthorization. When i upload the lambda in the cloud it works fine. The problem only exist when i serve the lambda locally