-
Notifications
You must be signed in to change notification settings - Fork 407
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
I get Content-Type: text/html if i return a response in a middleware with a async body.
import { Response } from 'undici';
return new Response(bodyStream.iterator(), {
status: 200,
statusText: 'OK',
headers: {'content-type': 'application/json'},
});
If the bodyStream is not async it does work.
import { Response } from 'undici';
const streamToBuffer = async (stream: Stream): Promise<Buffer> => {
return new Promise<Buffer>((resolve, reject) => {
const list: Array<Uint8Array> = [];
stream.on('data', (chunk) => list.push(chunk));
stream.on('end', () => resolve(Buffer.concat(list)));
stream.on('error', (error) => reject(error));
});
};
return new Response(await streamToBuffer(bodyStream), {
status: 200,
statusText: 'OK',
headers: {'content-type': 'application/json'},
});
Expected behavior 🤔
I expect that the content-type passed as a headers is maintained in async and sync bodies on response.
Steps to reproduce 🕹
Steps:
- Create a Middleware
- Return a Response (undici) with a async bodyInit and a headersInit with a content-type for example 'application/json'
- Do a request which hits the middleware and check the content-type on the response.
Context 🔦
No response
Your environment 🌎
System:
OS: Fedora 39
CPU: x86_64
Binaries:
Node: 20.11.1 (/run/user/1000/fnm_multishells/128003_1711479810299/bin/node)
pnpm: 8.15.4 (/run/user/1000/fnm_multishells/128003_1711479810299/bin/pnpm)
npmPackages:
all of solid start +
"undici": "^6.10.2"
"undici-types": "^6.10.1"Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working