Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Oct 23, 2025

close #5638

@fengmk2 fengmk2 requested a review from Copilot October 23, 2025 14:47
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch koa-pick-1893

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.

@cloudflare-workers-and-pages
Copy link

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: ccee62a
Status: ✅  Deploy successful!
Preview URL: https://91f3d7df.egg-cci.pages.dev
Branch Preview URL: https://koa-pick-1893.egg-cci.pages.dev

View logs

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 58.53659% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.44%. Comparing base (97372fd) to head (ccee62a).
⚠️ Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
packages/koa/src/response.ts 26.66% 8 Missing and 3 partials ⚠️
packages/koa/src/utils.ts 45.45% 6 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (97372fd) and HEAD (ccee62a). Click for more details.

HEAD has 15 uploads less than BASE
Flag BASE (97372fd) HEAD (ccee62a)
25 10
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5641      +/-   ##
==========================================
- Coverage   87.52%   80.44%   -7.09%     
==========================================
  Files         565      534      -31     
  Lines       11007    10675     -332     
  Branches     1243     1225      -18     
==========================================
- Hits         9634     8587    -1047     
- Misses       1291     1942     +651     
- Partials       82      146      +64     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages
Copy link

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: ccee62a
Status: ✅  Deploy successful!
Preview URL: https://dad6e221.egg-v3.pages.dev
Branch Preview URL: https://koa-pick-1893.egg-v3.pages.dev

View logs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for Blob and Response objects as body types in the Koa framework, addressing issue #5638. The changes introduce handling for web standard API types (Blob, Response, ReadableStream) alongside traditional Node.js streams.

Key changes:

  • Added support for Blob, Response, and ReadableStream as response body types
  • Renamed internal classes (ContextKoaContext, RequestKoaRequest, ResponseKoaResponse) to avoid naming conflicts with web standard Response
  • Migrated from direct stream piping to Stream.pipeline for better error handling and stream cleanup

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/koa/src/application.ts Updated class names and added stream handling via Stream.pipeline for Blob/Response/ReadableStream
packages/koa/src/context.ts Renamed Context to KoaContext and updated type references
packages/koa/src/request.ts Renamed Request to KoaRequest and updated type references
packages/koa/src/response.ts Added body type handling for Blob/Response/ReadableStream; renamed Response to KoaResponse
packages/koa/src/index.ts Updated exports with deprecation notices for backward compatibility
packages/koa/src/utils.ts Added isStream() utility function for stream type checking
packages/koa/test/application/respond.test.ts Added comprehensive tests for Response, ReadableStream, and pipeline error handling
packages/koa/test/response/body.test.ts Updated test expectations for stream error handling behavior
packages/koa/test/__snapshots__/index.test.ts.snap Updated snapshot with new exported class names

this.status = val.status;
if (setType) this.type = 'bin';
const headers = val.headers;
console.log('headers', headers);
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug console.log statement should be removed before merging to production. This appears to be leftover debugging code that will pollute production logs.

Suggested change
console.log('headers', headers);

Copilot uses AI. Check for mistakes.
describe('when using pipeline for streams', () => {
it('should handle stream errors when error listener exists', async () => {
const app = new Koa();
const PassThrough = require('stream').PassThrough;
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ES6 import syntax instead of require() to maintain consistency with the rest of the codebase which uses TypeScript imports (e.g., import { PassThrough } from 'node:stream').

Copilot uses AI. Check for mistakes.

it('should not crash when stream errors and no error listener exists', async () => {
const app = new Koa();
const PassThrough = require('stream').PassThrough;
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ES6 import syntax instead of require() to maintain consistency with the rest of the codebase which uses TypeScript imports (e.g., import { PassThrough } from 'node:stream').

Copilot uses AI. Check for mistakes.

it('should cleanup streams on client abort', async () => {
const app = new Koa();
const PassThrough = require('stream').PassThrough;
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ES6 import syntax instead of require() to maintain consistency with the rest of the codebase which uses TypeScript imports (e.g., import { PassThrough } from 'node:stream').

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +136
const shouldDestroyOriginal = original && isStream(original);
if (shouldDestroyOriginal) {
// Ignore errors during cleanup to prevent unhandled exceptions when destroying the stream
original.once('error', () => {});
destroy(original);
}
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The variable shouldDestroyOriginal is only used once immediately after declaration. Consider simplifying by using the condition directly in the if statement: if (original && isStream(original)).

Copilot uses AI. Check for mistakes.
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.

sync koa stream fix

2 participants