Skip to content

Node.js compat — Request body/Response can not be initialized with a Readable #2746

@vicb

Description

@vicb

Repro:

import { Readable } from 'node:stream';

export default {
	async fetch() {
		const rNode = new Request('https://example.com', {
			method: 'POST',
			body: Readable.from([...'node']),
		});

		for await (const l of rNode.body!) {
			console.log(l);
		}

		const rWeb = new Request('https://example.com', {
			method: 'POST',
			body: ReadableStream.from([...'web']),
		});

		for await (const l of rWeb.body!) {
			console.log(l);
		}
		return new Response('done');
	},
};

Logs:

Uint8Array(15) [
   91, 111, 98, 106, 101,
   99, 116, 32,  79,  98,
  106, 101, 99, 116,  93
] // "[object Object]"

w
e
b

Node (/undici) have extra support for AsyncIterable<Uint8Array>, Iterable<Uint8Array>, and null for BodyInit

Response can also be initialized with a BodyInit, i.e. return new Response(bodyInit); so we should also update the response in the same way

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions