Conversation
WalkthroughAdjusts stream handling to apply set mutations (headers/cookies) before awaiting the generator’s first yield in createStreamHandler. Adds a test verifying multiple Set-Cookie headers are included in streamed SSE responses when cookies are set prior to the first chunk. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant H as createStreamHandler
participant S as handleSet(set)
participant G as Stream Generator
participant R as Response
Note over H: New flow: apply set before first yield
C->>H: HTTP request (SSE)
H->>S: Apply headers/cookies from set
S-->>H: Set mutations applied
H->>G: Start generator
G-->>H: First yield (SSE chunk)
H->>R: Send headers (incl. Set-Cookie) + first chunk
loop Subsequent chunks
G-->>H: Next yield
H-->>R: Stream chunk
end
G-->>H: Complete
H-->>C: Stream closed
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (2)src/adapter/utils.ts (1)
test/response/stream.test.ts (2)
🔇 Additional comments (2)
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. Comment |
Fix #1434
Problem
When using generator functions (streaming responses) with cookies in ElysiaJS, the set-cookie headers were not being included in the HTTP response headers. This occurred because cookies set via context.cookie['name'].set() before yielding the first chunk were not processed and added to the response headers.
Root Cause
The createStreamHandler function in src/adapter/utils.ts was not calling handleSet() to process cookies and other context properties before creating the Response object. The handleSet() function is responsible for serializing cookies from context.set.cookie into proper set-cookie headers.
Solution
Added a call to handleSet(set) in the createStreamHandler function before the generator starts processing, ensuring that cookies are properly serialized and included in the response headers.
Summary by CodeRabbit
Bug Fixes
Tests