Closed davidkarlsen closed 3 years ago
Hmm, I see offsets interleaved with the data:
48<--
Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /x
0<--
Try setting transfer-encoding: identity on the response headers before handing it off to the application framework
hmm, where do you mean to do this? the flow is:
api-gw -> lambda (which uses this lib via https://github.com/http-party/node-http-proxy) -> backend (which sets transfer-encoding chunked)
you mean I can set transfer-encoding: identity
instead of chunked
when the response passes through the lambda?
Just as an experiment, try here: https://github.com/dougmoscrop/serverless-http/blob/master/lib/framework/get-framework.js#L8
response.setHeader('...')
Didn't seem to have any impact.
Yeah; I imagine the right thing to do here, unfortunately, is to read+understand the chunked encoding and strip out the chunks before handing it back from Lambda to API Gateway. If I'm not mistaken, that's how the HTTP spec actually expects intermediary nodes to work although I haven't exhaustively looked in to this. I'm happy to try to help here, I just have, literally, a dozen competing priorities right now, so if you do have cycles please keep it up and I will merge anything that improves the situation, but I'm not convinced removing the error is going to make peoples lives easier (maybe a link to this PR/issue in the error message, would be helpful)
Yes. Agree - I was a bit quick to conclude it worked. A bit surprised AWS api gw is like it is.
So to be fair, the blame falls solely on this library. If you were just writing a "plain Lambda", you'd be returning:
{ "statusCode": 200, "headers": { }, "body": "hello" }
aws-serverless-express actually runs a node server inside your lambda, that it talks to on localhost, and so it deserializes/reserializes multiple times to send the request and get the response before handing it back which gives it a bit of an edge that way. this library is creating http.IncomingMessage/ServerResponse objects, and it's the frameworks themselves sending back chunked responses, that normally the http client would strip out.
We can solve this, I'm sure
See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html for documentation on the header. I just tried the patched library, and I get the response in return just fine.
This change is