Skip to content

fix: set content type header consistently for responses api requests - #4935

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
07-06-fix_set_content_type_header_consistently_for_responses_api_requests
Jul 6, 2026
Merged

fix: set content type header consistently for responses api requests#4935
Pratham-Mishra04 merged 1 commit into
devfrom
07-06-fix_set_content_type_header_consistently_for_responses_api_requests

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

The Content-Type: application/json header was previously only set when the request method was POST or when a body was present. This meant non-POST requests with no body (e.g., GET or DELETE) would not include the header, which could cause inconsistent behavior. The header is now always set regardless of method or body presence.

Changes

  • Removed the outer conditional that gated Content-Type: application/json on the method being POST or the body being non-empty
  • The header is now unconditionally set on all requests in executeResponsesLifecycleUnary
  • Body assignment logic remains unchanged: a provided body is used as-is, and an empty POST body defaults to {}

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./core/providers/openai/...

Verify that requests made via the OpenAI Responses lifecycle (including non-POST methods) include the Content-Type: application/json header, and that POST requests with no body still default to {}.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

No security implications. This change only affects request header construction.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@TejasGhatte
TejasGhatte marked this pull request as ready for review July 6, 2026 06:54

TejasGhatte commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Content-Type header setting in executeResponsesLifecycleUnary was refactored to always apply application/json regardless of HTTP method or body content, while body defaulting behavior for empty POST requests remains unchanged.

Changes

Content-Type Header Fix

Layer / File(s) Summary
Unconditional Content-Type assignment
core/providers/openai/responseslifecycle.go
Content-Type is now always set to application/json for lifecycle requests, removing the prior conditional that skipped it for non-POST requests with empty bodies, while body defaulting ({} for empty POST bodies) is preserved.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR changes request header behavior, but #123 requires Files API support such as POST /v1/files, so the objective is not implemented. Implement the file upload API support required by #123, or relink the PR if this header fix is meant for a different issue.
Out of Scope Changes check ⚠️ Warning The only code change is unrelated to the linked Files API support issue and does not address the requested file upload functionality. Remove the unrelated header-only changes or update the linked issue to match the actual scope of this PR.
Description check ⚠️ Warning The description is just the template and lacks any actual summary, changes, testing, or issue details. Replace the template text with a real PR summary, changes, testing steps, affected areas, and links to related issues.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly matches the code change: consistently setting the Content-Type header for Responses API requests.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-06-fix_set_content_type_header_consistently_for_responses_api_requests

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

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

One-line simplification that aligns header-setting behaviour with the rest of the OpenAI provider; no logic is removed, no new paths are introduced.

The change removes a conditional guard so Content-Type is set unconditionally, which matches every other HTTP call site in openai.go and large_payload.go. GET and DELETE requests to OpenAI tolerate the header without a body, and the body-setting logic itself is untouched. The blast radius is limited to the four Responses lifecycle methods.

No files require special attention.

Important Files Changed

Filename Overview
core/providers/openai/responseslifecycle.go Unconditionally sets Content-Type: application/json before every outbound HTTP call, matching the pattern used throughout openai.go and large_payload.go. Body-setting logic is logically unchanged.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[executeResponsesLifecycleUnary] --> B[SetRequestURI + SetMethod]

    subgraph BEFORE["Before (original logic)"]
        B1{method == POST\nor len body > 0?}
        B1 -->|Yes| B2[SetContentType application/json]
        B2 --> B3{len body > 0?}
        B3 -->|Yes| B4[SetBody body]
        B3 -->|No| B5{method == POST?}
        B5 -->|Yes| B6["SetBody {}"]
        B1 -->|No| B7[No Content-Type set\nNo body set]
    end

    subgraph AFTER["After (this PR)"]
        A2[SetContentType application/json - always]
        A2 --> A3{len body > 0?}
        A3 -->|Yes| A4[SetBody body]
        A3 -->|No| A5{method == POST?}
        A5 -->|Yes| A6["SetBody {}"]
        A5 -->|No| A7[No body set but Content-Type still set]
    end

    B --> B1
    B --> A2
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[executeResponsesLifecycleUnary] --> B[SetRequestURI + SetMethod]

    subgraph BEFORE["Before (original logic)"]
        B1{method == POST\nor len body > 0?}
        B1 -->|Yes| B2[SetContentType application/json]
        B2 --> B3{len body > 0?}
        B3 -->|Yes| B4[SetBody body]
        B3 -->|No| B5{method == POST?}
        B5 -->|Yes| B6["SetBody {}"]
        B1 -->|No| B7[No Content-Type set\nNo body set]
    end

    subgraph AFTER["After (this PR)"]
        A2[SetContentType application/json - always]
        A2 --> A3{len body > 0?}
        A3 -->|Yes| A4[SetBody body]
        A3 -->|No| A5{method == POST?}
        A5 -->|Yes| A6["SetBody {}"]
        A5 -->|No| A7[No body set but Content-Type still set]
    end

    B --> B1
    B --> A2
Loading

Reviews (1): Last reviewed commit: "fix: set content type header consistentl..." | Re-trigger Greptile

Pratham-Mishra04 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Merge activity

  • Jul 6, 7:20 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 6, 7:21 AM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 merged commit ca8fbd4 into dev Jul 6, 2026
15 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 07-06-fix_set_content_type_header_consistently_for_responses_api_requests branch July 6, 2026 07:21
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.

3 participants