Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/cloudflare/src/utils/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type StreamingGuess = {
* Heuristics:
* - No body → not streaming
* - Known streaming Content-Types → streaming (SSE, NDJSON, JSON streaming)
* - text/plain without Content-Length → streaming (some AI APIs)
* - Otherwise → not streaming (conservative default, including HTML/SSR)
*
* We avoid probing the stream to prevent blocking on transform streams (like injectTraceMetaTags)
Expand All @@ -20,18 +19,15 @@ export function classifyResponseStreaming(res: Response): StreamingGuess {
}

const contentType = res.headers.get('content-type') ?? '';
const contentLength = res.headers.get('content-length');

// Streaming: Known streaming content types
// - text/event-stream: Server-Sent Events (Vercel AI SDK, real-time APIs)
// - application/x-ndjson, application/ndjson: Newline-delimited JSON
// - application/stream+json: JSON streaming
// - text/plain (without Content-Length): Some AI APIs use this for streaming text
if (
/^text\/event-stream\b/i.test(contentType) ||
/^application\/(x-)?ndjson\b/i.test(contentType) ||
/^application\/stream\+json\b/i.test(contentType) ||
(/^text\/plain\b/i.test(contentType) && !contentLength)
/^application\/stream\+json\b/i.test(contentType)
) {
return { isStreaming: true };
}
Expand Down
6 changes: 1 addition & 5 deletions packages/deno/src/utils/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type StreamingGuess = {
* Heuristics:
* - No body → not streaming
* - Known streaming Content-Types → streaming (SSE, NDJSON, JSON streaming)
* - text/plain without Content-Length → streaming (some AI APIs)
* - Otherwise → not streaming (conservative default, including HTML/SSR)
*
* We avoid probing the stream to prevent blocking on transform streams (like injectTraceMetaTags)
Expand All @@ -22,18 +21,15 @@ export function classifyResponseStreaming(res: Response): StreamingGuess {
}

const contentType = res.headers.get('content-type') ?? '';
const contentLength = res.headers.get('content-length');

// Streaming: Known streaming content types
// - text/event-stream: Server-Sent Events (Vercel AI SDK, real-time APIs)
// - application/x-ndjson, application/ndjson: Newline-delimited JSON
// - application/stream+json: JSON streaming
// - text/plain (without Content-Length): Some AI APIs use this for streaming text
if (
/^text\/event-stream\b/i.test(contentType) ||
/^application\/(x-)?ndjson\b/i.test(contentType) ||
/^application\/stream\+json\b/i.test(contentType) ||
(/^text\/plain\b/i.test(contentType) && !contentLength)
/^application\/stream\+json\b/i.test(contentType)
) {
return { isStreaming: true };
}
Expand Down
Loading