Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-length not properly set #129

Closed
JonathanJonathanJonathan opened this issue Mar 8, 2018 · 1 comment
Closed

Content-length not properly set #129

JonathanJonathanJonathan opened this issue Mar 8, 2018 · 1 comment

Comments

@JonathanJonathanJonathan
Copy link

JonathanJonathanJonathan commented Mar 8, 2018

If you try to load an image it will calculate the content-length by taking the length of the body buffer
https://github.com/awslabs/aws-serverless-express/blob/500f04ead08ae057062b9bbeb3292eeb46ce54e1/index.js#L59

Later the body buffer is converted to a string, resulting in a different content-length https://github.com/awslabs/aws-serverless-express/blob/500f04ead08ae057062b9bbeb3292eeb46ce54e1/index.js#L84, so the length won't match. Which results in an ERR_CONTENT_LENGTH_MISMATCH error in the browser.

See screenshot:
bug

I fixed it by adding
if(isBase64Encoded && typeof headers['content-length'] !== "undefined") { headers['content-length'] = body.length.toString() }
after https://github.com/awslabs/aws-serverless-express/blob/500f04ead08ae057062b9bbeb3292eeb46ce54e1/index.js#L84

Not sure if this is a decent fix or if I'm missing something :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants