dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 165 forks source link

res.writeHead ignoring headers (2.3.0) #157

Closed BaukePalstra closed 4 years ago

BaukePalstra commented 4 years ago

When implementing res.writeHead, I get no headers back in my response: (req, res) => { res.writeHead(301, { Location: ' /foo', }) res.end() } results in this response: { "statusCode": 301, "headers": {}, "isBase64Encoded": false, "body": "" }

This is working fine without serverless http (ServerResponse instead of ServerlessResponse).

I suspect it has to do with https://github.com/dougmoscrop/serverless-http/blob/master/lib/response.js#L41, since the key is named _header, instead of _headers .

Refactoring to res.setHeader('Location', ' /foo') res.statusCode = 301 res.end() does give the response I expect

dougmoscrop commented 4 years ago

I added a test that shows this is working - can you double-check? https://github.com/dougmoscrop/serverless-http/blob/master/test/spec.js#L400

BaukePalstra commented 4 years ago

Sorry for the late reply. I see that in the 2.3.1 (title wrongfully says 2.3.0) version, writeHead wasn't working. I've added your test to that version (locally), but it errs: image

Indeed looks like everything is ok in the latest version 👍

dougmoscrop commented 4 years ago

Great! So OK to close this?