Skip to content

fix(aws-lambda-streaming): handle empty body#205

Open
taylorfsteele wants to merge 1 commit into
h3js:mainfrom
taylorfsteele:fix/aws-lambda-streaming-body
Open

fix(aws-lambda-streaming): handle empty body#205
taylorfsteele wants to merge 1 commit into
h3js:mainfrom
taylorfsteele:fix/aws-lambda-streaming-body

Conversation

@taylorfsteele
Copy link
Copy Markdown

@taylorfsteele taylorfsteele commented May 14, 2026

Resolves #204

When the request body is null the response stream doesn't close. This breaks responses like redirects that don't have a body:

return new Response(null, {
   status: 302,
   headers: {
     location: "/",
   },
});

This PR adds in the conditional logic to create a response body if none exists.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced handling of AWS Lambda responses that lack a response body, ensuring proper stream closure and metadata delivery
    • Improved streaming behavior for responses without body content (such as redirects), maintaining correct status codes and headers in the stream

Review Change Stack

@taylorfsteele taylorfsteele requested a review from pi0 as a code owner May 14, 2026 21:09
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1e793dd0-0997-406c-aa9d-596aa1703a85

📥 Commits

Reviewing files that changed from the base of the PR and between c853aa9 and 08375ab.

📒 Files selected for processing (2)
  • src/adapters/_aws/utils.ts
  • test/aws.test.ts

📝 Walkthrough

Walkthrough

This PR fixes AWS Lambda streaming responses that lack bodies (such as redirects). The awsStreamResponse utility now creates a default empty ReadableStream when the response body is absent, ensuring the metadata and stream close operations complete rather than returning early. Tests verify the empty-string chunk is written and writer.end() is called for both empty bodies and redirect scenarios.

Changes

AWS Lambda Streaming Response Handling

Layer / File(s) Summary
Handle missing response bodies
src/adapters/_aws/utils.ts
awsStreamResponse substitutes an empty ReadableStream when response.body is absent, replacing the early return pattern and allowing streaming to proceed through the full try/finally flow.
Test empty body streaming behavior
test/aws.test.ts
Updated empty-body test now asserts a single empty-string chunk is written and writer.end() is called; new test validates redirect (302) responses without bodies stream metadata and close correctly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • h3js/srvx#104: Introduced the core AWS Lambda adapter utilities including the awsStreamResponse function that this PR now extends to handle missing response bodies.

Suggested reviewers

  • pi0

Poem

🐰 A stream without a body, who knew?
Now redirects fly through clean and true,
Empty reads create the flow,
Metadata writes put on a show,
Lambda's Lambda, all fixed anew! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(aws-lambda-streaming): handle empty body' is concise, specific, and accurately describes the primary change—handling AWS Lambda streaming responses when the body is absent or null.
Linked Issues check ✅ Passed The PR successfully addresses issue #204 by implementing conditional logic to create a default empty ReadableStream when response.body is absent, allowing streaming responses without bodies to complete correctly without timing out.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the AWS Lambda streaming body handling issue: the utils function implementation handles empty bodies, and test updates verify the fix for both empty bodies and redirect responses.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Aws Lambda Streaming responses don't work without response bodies.

1 participant