Skip to content

[FSSDK-12759] fix content-length header in NodeRequestHandler#1156

Open
raju-opti wants to merge 2 commits into
masterfrom
raju/content-length-fix
Open

[FSSDK-12759] fix content-length header in NodeRequestHandler#1156
raju-opti wants to merge 2 commits into
masterfrom
raju/content-length-fix

Conversation

@raju-opti

Copy link
Copy Markdown
Contributor

Summary

  • prevously, body.length was being used for content-length header, which is incorrect (The length data property of a String value contains the length of the string in UTF-16 code units, we need the byte length of utf-8 endcoded string). This PR fixes it.

Test plan

  • added tests
  • also tested with real node/python servers

Issues

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect Content-Length calculation in the Node RequestHandler by switching from UTF-16 code-unit length (string.length) to UTF-8 byte length (Buffer.byteLength), preventing request-body truncation for multi-byte payloads.

Changes:

  • Compute content-length using Buffer.byteLength(data) instead of data.length.
  • Simplify request body sending by using request.end(data) rather than write() + end().
  • Add integration-style tests that POST ASCII, emoji, and CJK JSON to a local HTTP server and assert the full body is received.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/utils/http_request_handler/request_handler.node.ts Corrects Content-Length to use UTF-8 byte length and sends the body via request.end(data).
lib/utils/http_request_handler/request_handler.node.spec.ts Adds regression tests using a real local HTTP server to validate multi-byte payloads aren’t truncated.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 77.759% (+0.05%) from 77.713% — raju/content-length-fix into master

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.

3 participants