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
Creating a
new Requestfrom a proxy fails withTypeError: Invalid URL: [object Request]Repro code on a worker:
The output is:
The same code:
Works well in Node and generate the following output:
I believe this issue linked to #5476 and #5711 that implement something that does not match the Node.js behavior.
/cc @jasnell