Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report — Request body can not be initialized with a Readable #2746

Open
vicb opened this issue Sep 19, 2024 · 2 comments
Open

🐛 Bug Report — Request body can not be initialized with a Readable #2746

vicb opened this issue Sep 19, 2024 · 2 comments

Comments

@vicb
Copy link

vicb commented Sep 19, 2024

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

@mhart
Copy link
Collaborator

mhart commented Sep 19, 2024

Just a comment to say I think we should only do this in node compat mode. That's all we need it for – and that reduces the surface area for issues – especially if ppl start relying on it in non-Node contexts

@mhart
Copy link
Collaborator

mhart commented Sep 19, 2024

Also, while we're at it – should we throw for any non-supported type passed as the body? Seems we're calling .toString on it if we don't recognise it (would be my guess?). Not sure if that's the spec – if not, might help people track down issues a bit easier. Would need a compat flag though in case anyone was relying on that.

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

No branches or pull requests

2 participants