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 response header incorrectly parsed #1275

Closed
kerim1 opened this issue Nov 30, 2018 · 3 comments
Closed

Content length response header incorrectly parsed #1275

kerim1 opened this issue Nov 30, 2018 · 3 comments

Comments

@kerim1
Copy link

kerim1 commented Nov 30, 2018

When requesting the length using ctx.length, Koa parses the content length response header using the double tilde operator: https://github.com/koajs/koa/blob/master/lib/response.js#L214 However, this operation also performs a 32-bit conversion, resulting in incorrect and weird results when serving large files. Isn't it therefore better to use the Math.trunc() function instead to parse the content length response header?

@fl0w
Copy link
Contributor

fl0w commented Nov 30, 2018

Or BigInt for node >=10.4.

@tpscrpt
Copy link
Contributor

tpscrpt commented Dec 20, 2018

using Math.trunc is 5% slower on 100 000 000 iterations of res.length when it's set to 164 chars.

@fl0w
Copy link
Contributor

fl0w commented Dec 31, 2018

Fixed in 9be8583

@fl0w fl0w closed this as completed Dec 31, 2018
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

3 participants