Skip to content

fix(api): flagsmith api doesn't send a default content type - #80

Merged
khvn26 merged 1 commit into
mainfrom
fix/api-default-content-type
Aug 11, 2026
Merged

fix(api): flagsmith api doesn't send a default content type#80
khvn26 merged 1 commit into
mainfrom
fix/api-default-content-type

Conversation

@khvn26

@khvn26 khvn26 commented Aug 11, 2026

Copy link
Copy Markdown
Member

Closes #79.

Content-Type: application/json was set only for a body built from -F/-f. A body read verbatim from --input went out with no content type, so the API parses nothing and the request fails as if the fields were missing.

In this PR, we:

  • Default the header whenever there is a request body.
  • Skip the default when -H already carries a Content-Type (previously a user-supplied one was appended to the field-body default, sending two values).

Tests: the existing stdin-body case now asserts the content type, plus a new case for the -H override.

`Content-Type: application/json` was set only for a body built from
-F/-f fields. A body read verbatim from --input went out with no content
type at all, so DRF parses nothing and the request fails as if the
fields were missing.

Default the header whenever there is a body, and skip the default when
-H already carries a Content-Type — previously a user-supplied one was
appended to the field-body default, sending two values. A bodiless
GET/DELETE still sends no content type: on a request with no content the
header has no meaning.

beep boop
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fff1bc8a-cac0-4c5e-ae33-8315059e7b1f

📥 Commits

Reviewing files that changed from the base of the PR and between 5bda84a and 194eda1.

📒 Files selected for processing (2)
  • internal/cmd/api.go
  • internal/cmd/cmd_test.go

📝 Walkthrough

Walkthrough

The API command no longer returns a content type from apiRequestBody. The command passes request headers to apiDo, which sets Content-Type: application/json for non-nil bodies when no explicit content type exists. This includes bodies read through --input. Explicit Content-Type headers remain unchanged. Tests cover the default JSON content type and an explicit form-encoded override.

Estimated code review effort: 2 (Simple) | ~10 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khvn26
khvn26 merged commit 21ea585 into main Aug 11, 2026
9 checks passed
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.

flagsmith api doesn't send default content-type

2 participants