diff --git a/src/core.ts b/src/core.ts index 10b9d3f..849954b 100644 --- a/src/core.ts +++ b/src/core.ts @@ -288,24 +288,6 @@ export abstract class APIClient { return this.requestAPIList(Page, { method: 'get', path, ...opts }); } - private calculateContentLength(body: unknown): string | null { - if (typeof body === 'string') { - if (typeof Buffer !== 'undefined') { - return Buffer.byteLength(body, 'utf8').toString(); - } - - if (typeof TextEncoder !== 'undefined') { - const encoder = new TextEncoder(); - const encoded = encoder.encode(body); - return encoded.length.toString(); - } - } else if (ArrayBuffer.isView(body)) { - return body.byteLength.toString(); - } - - return null; - } - async buildRequest( inputOptions: FinalRequestOptions, { retryCount = 0 }: { retryCount?: number } = {}, @@ -319,8 +301,6 @@ export abstract class APIClient { : isMultipartBody(options.body) ? options.body.body : options.body ? JSON.stringify(options.body, null, 2) : null; - const contentLength = this.calculateContentLength(body); - const url = this.buildURL(path!, query, defaultBaseURL); if ('timeout' in options) validatePositiveInteger('timeout', options.timeout); options.timeout = options.timeout ?? this.timeout; @@ -342,7 +322,7 @@ export abstract class APIClient { headers[this.idempotencyHeader] = inputOptions.idempotencyKey; } - const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount }); + const reqHeaders = this.buildHeaders({ options, headers, retryCount }); const req: RequestInit = { method, @@ -365,13 +345,9 @@ export abstract class APIClient { }: { options: FinalRequestOptions; headers: Record; - contentLength: string | null | undefined; retryCount: number; }): Record { const reqHeaders: Record = {}; - if (contentLength) { - reqHeaders['content-length'] = contentLength; - } const defaultHeaders = this.defaultHeaders(options); applyHeadersMut(reqHeaders, defaultHeaders); diff --git a/tests/index.test.ts b/tests/index.test.ts index 7639b23..b2b00d5 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -237,14 +237,9 @@ describe('request building', () => { const client = new Browserbase({ apiKey: 'My API Key' }); describe('Content-Length', () => { - test('handles multi-byte characters', async () => { - const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { value: '—' } }); - expect((req.headers as Record)['content-length']).toEqual('20'); - }); - - test('handles standard characters', async () => { + test('lets fetch compute the request content length', async () => { const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { value: 'hello' } }); - expect((req.headers as Record)['content-length']).toEqual('22'); + expect(req.headers as Record).not.toHaveProperty('content-length'); }); });