Skip to content

fix(client): omit Content-Type on DELETE requests - #198

Open
edenbuilds wants to merge 2 commits into
browserbase:mainfrom
edenbuilds:fix/delete-no-content-type
Open

fix(client): omit Content-Type on DELETE requests#198
edenbuilds wants to merge 2 commits into
browserbase:mainfrom
edenbuilds:fix/delete-no-content-type

Conversation

@edenbuilds

Copy link
Copy Markdown

Summary

Fixes #180

Test plan

  • Unit tests: DELETE request headers lack content-type; POST still gets application/json
  • A/B: without the core.ts change, DELETE test fails with content-type: application/json; with fix, both tests pass

Made with Cursor

defaultHeaders set Content-Type: application/json for every non-GET/HEAD
method, including bodyless DELETE. That makes contexts.delete() (and any
other DELETE) fail with 400 "Body cannot be empty when content-type is
set to application/json" — the same class of bug as extensions.delete
(browserbase#169 / browserbase#180).

Exclude delete alongside get and head when applying the default
Content-Type header.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08982a7824

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/core.ts Outdated
return {
Accept: 'application/json',
...(['head', 'get'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),
...(['head', 'get', 'delete'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve JSON content type for DELETE requests with bodies

When a caller uses the supported generic API for a JSON-bearing request such as client.delete('/some/path', { body: { ... } }), buildRequest still serializes and sends that body, but this method-only condition now omits Content-Type: application/json. Fetch implementations may consequently label the serialized string as text/plain or leave it untyped, causing DELETE endpoints that parse JSON to reject or misinterpret the request. Omit the header only when the DELETE request has no body rather than for every DELETE.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed — DELETE with a body keeps Content-Type: application/json when a JSON body is present (method alone no longer strips it).

Bodyless DELETE still omits Content-Type (browserbase#180). DELETE with a JSON
body restores application/json so fetch does not treat it as text/plain.
@edenbuilds

Copy link
Copy Markdown
Author

Addressed Codex P2: bodyless DELETE still omits `Content-Type` (#180), but DELETE with a JSON body now keeps `application/json`. Added a regression test for both cases.

@edenbuilds

Copy link
Copy Markdown
Author

Codex P2 is addressed in `14d7925`: bodyless DELETE still omits `Content-Type` (#180), but DELETE with a JSON body keeps `application/json`. Regression tests cover both paths.

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.

[Bug] contexts.delete() fails with 400 — same Content-Type issue as extensions.delete() (#169)

1 participant