Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,15 @@ export abstract class APIClient {
* }
*/
protected defaultHeaders(opts: FinalRequestOptions): Headers {
// Omit default JSON Content-Type for bodyless methods. DELETE still needs
// application/json when the caller sends a body (#180 / Codex follow-up).
const omitDefaultContentType =
opts.method === 'head' ||
opts.method === 'get' ||
(opts.method === 'delete' && (opts.body === undefined || opts.body === null));
return {
Accept: 'application/json',
...(['head', 'get'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),
...(omitDefaultContentType ? {} : { 'Content-Type': 'application/json' }),
'User-Agent': this.getUserAgent(),
...getPlatformHeaders(),
...this.authHeaders(opts),
Expand Down
31 changes: 31 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,37 @@ describe('instantiate client', () => {
expect(capturedRequest?.method).toEqual('PATCH');
});

test('does not set Content-Type on DELETE (#180)', async () => {
const client = new Browserbase({
baseURL: 'http://localhost:5000/',
apiKey: 'My API Key',
});
const { req } = await client.buildRequest({ path: '/v1/contexts/id', method: 'delete' });
expect(req.headers as Headers).not.toHaveProperty('content-type');
});

test('sets Content-Type on DELETE when a JSON body is present', async () => {
const client = new Browserbase({
baseURL: 'http://localhost:5000/',
apiKey: 'My API Key',
});
const { req } = await client.buildRequest({
path: '/v1/contexts/id',
method: 'delete',
body: { force: true },
});
expect((req.headers as Headers)['content-type']).toEqual('application/json');
});

test('still sets Content-Type on POST', async () => {
const client = new Browserbase({
baseURL: 'http://localhost:5000/',
apiKey: 'My API Key',
});
const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { a: 1 } });
expect((req.headers as Headers)['content-type']).toEqual('application/json');
});

describe('baseUrl', () => {
test('trailing slash', () => {
const client = new Browserbase({ baseURL: 'http://localhost:5000/custom/path/', apiKey: 'My API Key' });
Expand Down