honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
18.5k stars 521 forks source link

Return a piped response with compression enabled causes an unexpected error #3316

Open ceifa opened 3 weeks ago

ceifa commented 3 weeks ago

What version of Hono are you using?

4.5.8

What runtime/platform is your app running on?

Node

What steps can reproduce the bug?

Enable the built-in compression:

app.use(compress());

Inside a hono route, do the following:

return await fetch(targetUrl, {
    method: req.method,
    headers,
    body: req.raw.body,
    duplex: 'half',
});

What is the expected behavior?

Response piped correctly.

What do you see instead?

TypeError: immutable at _Headers.delete (node:internal/deps/undici/undici:3303:17) at set res [as res] (file:///D:/whitewall/proxy/node_modules/hono/dist/context.js:62:31) at compress2 (file:///D:/whitewall/proxy/node_modules/hono/dist/middleware/compress/index.js:12:13)

Additional information

It works on latest version of 3.x. Stopped in 4.x.

nitedani commented 3 weeks ago

Edited