Skip to content
Merged
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
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@rspack/core": "2.2.9",
"@types/express": "^5.0.6",
"@types/node": "^24.19.2",
"@types/on-finished": "^2.3.5",
"@types/range-parser": "^1.2.7",
"connect-next": "^5.0.0",
"cspell": "^10.3.6",
Expand All @@ -50,7 +49,6 @@
"koa": "^3.2.1",
"memfs": "4.80.0",
"mrmime": "^2.0.1",
"on-finished": "^2.4.1",
"range-parser": "^1.3.0",
"router": "^2.2.0",
"rstack": "^0.8.3",
Expand Down
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/middleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import { finished } from "node:stream";

import { lookup, mimes } from "mrmime";
import onFinishedStream from "on-finished";
import rangeParser from "range-parser";

import {
Expand Down Expand Up @@ -920,7 +920,7 @@ function wrapper(context) {

if (outgoing) {
// Response finished, cleanup
onFinishedStream(outgoing, cleanup);
finished(outgoing, cleanup);
}
}

Expand Down
19 changes: 16 additions & 3 deletions test/middleware.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import { createServer } from "node:http";
import path from "node:path";
import { Readable } from "node:stream";

import Hapi from "@hapi/hapi";
import { serve } from "@hono/node-server";
Expand Down Expand Up @@ -3681,10 +3682,22 @@ describe.each([
});

it("should work with piping stream", async () => {
const response1 = await req.get("/file.text");
const stream = Readable.from(["text"], { autoDestroy: false });
const createReadStream = rs
.spyOn(instance.context.outputFileSystem, "createReadStream")
.mockReturnValue(stream);

expect(response1.statusCode).toBe(200);
expect(nextWasCalled).toBe(false);
try {
const response = await req.get("/file.text");

expect(response.statusCode).toBe(200);
expect(response.text).toBe("text");
expect(stream.destroyed).toBe(true);
expect(nextWasCalled).toBe(false);
} finally {
createReadStream.mockRestore();
stream.destroy();
}
});

it("should not allow to get files above root", async () => {
Expand Down
Loading