Skip to content

fix: claude header was not set correctly - #1767

Merged
Calcium-Ion merged 1 commit into
mainfrom
copy-claude-header-from-upstream
Sep 9, 2025
Merged

Calcium-Ion merged 1 commit into
mainfrom
copy-claude-header-from-upstream

Conversation

@creamlike1024

@creamlike1024 creamlike1024 commented Sep 9, 2025 •

Copy link
Copy Markdown
Collaborator

Fixes #1766

Summary by CodeRabbit

  • Bug Fixes

    • Client responses now correctly inherit the upstream Content-Type header for AWS relay results, preventing misclassification or rendering issues.
    • Headers are set before streaming the body to avoid header loss in responses.
    • Preserves upstream HTTP response context when returning Claude results, improving compatibility with clients and proxies.
  • Refactor

    • Streamlined response handling for Claude integrations to improve reliability without changing user-facing behavior.

@coderabbitai

coderabbitai Bot commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Upstream Content-Type from Anthropic/AWS responses is now propagated to client responses. The Claude response handler gained an extra parameter at its public entry and now accepts the upstream http.Response internally. Call sites were updated accordingly and the header is set before invoking the handler.

Changes

Cohort / File(s) Summary of Changes
AWS relay header propagation and call-site update
relay/channel/aws/relay-aws.go
Copy upstream Content-Type to client response when available. Updated claude.HandleClaudeResponseData invocation to 6 args (new 4th arg nil; body moved to 5th). Set header before calling handler.
Claude handler internal response wiring
relay/channel/claude/relay-claude.go
Added httpResp parameter to internal HandleClaudeResponseData and passed upstream resp through. IOCopyBytesGracefully now uses httpResp instead of nil. Minor whitespace only otherwise.
Public API signature change (Claude handler)
relay/channel/claude/*
Exported HandleClaudeResponseData signature extended: added 4th parameter (extra interface{}); body shifted to 5th; requestMode remains last. Call sites adjusted.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant R as NewAPI Relay
  participant U as Upstream (Anthropic/AWS)

  C->>R: POST /v1/messages
  R->>U: Forward request
  U-->>R: HTTP 200 + Body + Headers (Content-Type)

  rect rgba(230,245,255,0.6)
    note over R: Propagate upstream headers
    R->>R: Set Response Header: Content-Type = U.Content-Type
  end

  rect rgba(235,255,235,0.6)
    note over R: Handle/stream Claude response
    R->>R: HandleClaudeResponseData(ctx, info, claudeInfo, extra=nil, body, mode)
    R-->>C: Stream body (IOCopyBytesGracefully), preserving upstream context
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble bits of header hay,
Content-Type now hops the way—
From upstream fields to client’s view,
A tidy trail of bytes anew.
With gentle paws I stream the light,
Claude replies, all set just right.
Thump-thump: relay works tonight!

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 028f022 and c40a4f5.

📒 Files selected for processing (2)
  • relay/channel/aws/relay-aws.go (1 hunks)
  • relay/channel/claude/relay-claude.go (5 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copy-claude-header-from-upstream

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 and usage tips.

@Calcium-Ion
Calcium-Ion merged commit 18077b6 into main Sep 9, 2025
@Calcium-Ion
Calcium-Ion deleted the copy-claude-header-from-upstream branch October 11, 2025 03:06
@coderabbitai coderabbitai Bot mentioned this pull request Feb 2, 2026
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…er-from-upstream

fix: claude header was not set correctly
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…er-from-upstream

fix: claude header was not set correctly
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…er-from-upstream

fix: claude header was not set correctly
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.

Anthropic 端点 Response header 里的 Content-Type 未正确透传

2 participants