Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### v3.24.1 (2026-06-03)
* * *
### Bug Fixes:
- Fixed `Content-Length` header being computed from the JavaScript string length (UTF-16 code units) instead of the UTF-8 byte length. Requests with non-ASCII payloads (e.g. accented characters, CJK, emoji) under-declared `Content-Length` and were rejected by Node's `fetch`/undici (≥ 7.26.0) with `Request body length does not match content-length header`. The header is now computed via `Buffer.byteLength(data, 'utf8')`. Resolves https://github.com/chargebee/chargebee-node/issues/119.

### Tests:
- ASCII form-urlencoded body — `Content-Length` matches the UTF-8 byte length of the serialized body.
- Multi-byte JSON body — `Content-Length` matches the UTF-8 byte length and is greater than the JS character count, ensuring the regression cannot return.


### v3.24.0 (2026-05-04)
* * *
### New Resources:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.24.0
3.24.1
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chargebee",
"version": "3.24.0",
"version": "3.24.1",
"description": "A library for integrating with Chargebee.",
"scripts": {
"prepack": "npm install && npm run build",
Expand Down
2 changes: 1 addition & 1 deletion src/RequestWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class RequestWrapper {
const requestHeaders: RequestHeaders = { ...this.httpHeaders };
if (data && data.length) {
extend(true, requestHeaders, {
'Content-Length': data.length,
'Content-Length': Buffer.byteLength(data, 'utf8'),
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Environment = {
hostSuffix: '.chargebee.com',
apiPath: '/api/v2',
timeout: DEFAULT_TIME_OUT,
clientVersion: 'v3.24.0',
clientVersion: 'v3.24.1',
port: DEFAULT_PORT,
timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
exportWaitInMillis: DEFAULT_EXPORT_WAIT,
Expand Down
42 changes: 42 additions & 0 deletions test/requestWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,48 @@ describe('RequestWrapper - request headers', () => {
});
});

describe('Content-Length header', () => {
it('should set Content-Length to the UTF-8 byte length for ASCII form-urlencoded bodies', async () => {
responseFactory = () =>
new Response(JSON.stringify({ customer: { id: 'cust_123' } }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});

const chargebee = createChargebee();
await chargebee.customer.create({ first_name: 'John' });

const body = await capturedRequests[0].text();
const expected = Buffer.byteLength(body, 'utf8');
expect(capturedRequests[0].headers.get('Content-Length')).to.equal(
String(expected),
);
});

it('should set Content-Length to the UTF-8 byte length (not character count) for multi-byte JSON bodies', async () => {
responseFactory = () =>
new Response(JSON.stringify({ personalized_offers: [] }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});

const chargebee = createChargebee();
await chargebee.personalizedOffer.personalizedOffers({
customer_id: 'cust_123',
first_name: 'Jürgen',
last_name: 'Müller — 🎉',
});

const body = await capturedRequests[0].text();
const byteLength = Buffer.byteLength(body, 'utf8');
const charLength = body.length;
expect(byteLength).to.be.greaterThan(charLength);
expect(capturedRequests[0].headers.get('Content-Length')).to.equal(
String(byteLength),
);
});
});

describe('Lang-Version header', () => {
it('should set Lang-Version to the current Node.js process.version', async () => {
const chargebee = createChargebee();
Expand Down
Loading