I've encountered a scenario in which this library fails; Fastify with React Router (framework). It fails by returning an empty body.
I've done some debugging, and it seems to be caused by the code in:
|
if (headers['transfer-encoding'] === 'chunked' || response.chunkedEncoding) { |
|
const raw = Response.body(response).toString().split('\r\n'); |
|
const parsed = []; |
|
for (let i = 0; i < raw.length; i +=2) { |
|
const size = parseInt(raw[i], 16); |
|
const value = raw[i + 1]; |
|
if (value) { |
|
parsed.push(value.substring(0, size)); |
|
} |
|
} |
|
body = parsed.join('') |
|
} |
In this particular scenario the situation is as follows:
response.chunkedEncoding is false
headers['transfer-encoding'] is 'chunked'
- The body is NOT chunked:
- Parsing will fail
raw.length is 1
raw[0] is the actual body and so it not an integer (parseInt fails)
I've also noticed that headers['transfer-encoding'] is NOT removed; my understanding is that it should be.
I can make a PR with a suggested fix, but it probably needs input from someone with deeper knowledge that I have. For example, I don't know if the scenario I've described is bizarre in some way or if it is a bug in either Fastify or React Router.
I've encountered a scenario in which this library fails; Fastify with React Router (framework). It fails by returning an empty body.
I've done some debugging, and it seems to be caused by the code in:
serverless-http/lib/provider/aws/format-response.js
Lines 34 to 45 in 6c71eda
In this particular scenario the situation is as follows:
response.chunkedEncodingisfalseheaders['transfer-encoding']is'chunked'raw.lengthis1raw[0]is the actual body and so it not an integer (parseIntfails)I've also noticed that
headers['transfer-encoding']is NOT removed; my understanding is that it should be.I can make a PR with a suggested fix, but it probably needs input from someone with deeper knowledge that I have. For example, I don't know if the scenario I've described is bizarre in some way or if it is a bug in either Fastify or React Router.