Skip to content

fix(http1.1): compute Content-Length as a utf8 byte length - #394

Open
arpitjain099 wants to merge 1 commit into
Kong:masterfrom
arpitjain099:fix/content-length-utf8
Open

arpitjain099 wants to merge 1 commit into
Kong:masterfrom
arpitjain099:fix/content-length-utf8

Conversation

@arpitjain099

Copy link
Copy Markdown

Content-Length uses Buffer.byteLength(text, 'ascii'), which counts UTF-16 code units instead of bytes, so a text/plain body of äöü is 6 bytes on the wire but renders Content-Length: 3.

erunion diagnosed this in #332 on 2023-11-03, pointing at this line and the ascii encoding. Switching the encoding to utf8 is the whole fix.

The test drives HTTPSnippet.convert for the http/http1.1 client with a non-ascii body. Every body under src/fixtures/requests is ascii, where the two encodings agree, so nothing existing moved: 747 tests before, 748 after.

Fixes #332

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@arpitjain099

Copy link
Copy Markdown
Author

@erunion CLA signed

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

Successfully merging this pull request may close these issues.

Content-Length invalid for unicode text

3 participants