Skip to content

🐛 Bug Report — new Request(Proxy(request)) fails #6700

@vicb

Description

@vicb

Creating a new Request from a proxy fails with TypeError: Invalid URL: [object Request]

Repro code on a worker:

export default {
	async fetch(): Promise<Response> {
		const handler = {
			get(_target, prop, _receiver) {
				console.log('get', prop);
				return Reflect.get(...arguments);
			},
		};

		const proxy = new Proxy(new Request('http://ex.com'), handler);
		const clone = new Request(proxy);
		console.log(clone.url);

		return new Response(`Clone URL: ${clone.url}`);
	},
} satisfies ExportedHandler<Env>;

The output is:

get Symbol(Symbol.toPrimitive)
get toString
get Symbol(Symbol.toStringTag)
[wrangler:error] TypeError: Invalid URL: [object Request]

The same code:

const handler = {
	get(_target, prop, _receiver) {
		console.log('get', prop);
		return Reflect.get(...arguments);
	},
};

const proxy = new Proxy(new Request('http://ex.com'), handler);
const clone = new Request(proxy);
console.log(clone.url);

Works well in Node and generate the following output:

get Symbol(dispatcher)
get Symbol(state)
get Symbol(signal)
get Symbol(state)
http://ex.com/

I believe this issue linked to #5476 and #5711 that implement something that does not match the Node.js behavior.

/cc @jasnell

Metadata

Metadata

Assignees

Labels

No labels
No 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