Skip to content

fix: use HasPrefix for text/event-stream content-type check#201

Merged
jesse-engineer merged 1 commit into
ThinkInAIXYZ:mainfrom
jesse-engineer:fix/issue-200-content-type-event-stream
May 15, 2026
Merged

fix: use HasPrefix for text/event-stream content-type check#201
jesse-engineer merged 1 commit into
ThinkInAIXYZ:mainfrom
jesse-engineer:fix/issue-200-content-type-event-stream

Conversation

@jesse-engineer
Copy link
Copy Markdown
Collaborator

What type of PR is this?

bug fix

What this PR does

Fix the unexpected content type: text/event-stream; charset=utf-8 error when servers or reverse proxies (e.g., nginx) append ; charset=utf-8 to the Content-Type header.

Root Cause

In transport/streamable_http_client.go, the client checks Content-Type for text/event-stream using strict equality (==). When the server returns text/event-stream; charset=utf-8 (which is valid HTTP), the check fails and falls into the default case, producing the error.

The application/json check already uses strings.HasPrefix, but text/event-stream did not.

Changes

  • Line 124: Changed strict equality to !strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream")
  • Line 151: Changed strict equality to strings.HasPrefix(contentType, "text/event-stream")

Which issue(s) this PR fixes

Fixes #200

Some servers or reverse proxies (e.g., nginx) append '; charset=utf-8'
to the Content-Type header, resulting in 'text/event-stream; charset=utf-8'.
The strict equality check fails in this case, causing the error:
'unexpected content type: text/event-stream; charset=utf-8'.

Use strings.HasPrefix for text/event-stream check, consistent with how
application/json is already handled.

Fixes ThinkInAIXYZ#200
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
transport/streamable_http_client.go 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@jesse-engineer jesse-engineer merged commit 2139a0f into ThinkInAIXYZ:main May 15, 2026
6 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.

[BUG] unexpected content type: text/event-stream; charset=utf-8

2 participants