Incorrect JSON Content-Length for Unicode Text
Level 1 · node · API · Byte length calculation error
Scenario
An internal API gateway sends the JSON body and Content-Length header produced by a service without modification. English-only data works correctly, but some clients report truncated responses when a customer name or message contains UTF-8 text such as Korean or Japanese. The controller, JSON response service, and repository are separated.
Requirements
- Content-Length must equal the actual UTF-8 byte length of the transmitted JSON body\n- Preserve existing behavior for ASCII-only responses\n- Return the correct length when Korean, Japanese, or other multibyte text is present\n- Do not change the existing serialized JSON body to calculate its length\n- Preserve the 404 response for a missing customer
Acceptance criteria
- An ASCII customer response has a Content-Length equal to the UTF-8 body byte length
- A response containing a Korean name has a Content-Length equal to the actual body byte length
- A response containing a Japanese message has a Content-Length equal to the actual body byte length
- The JSON body itself is not changed to calculate Content-Length
- A request for a missing customer returns 404