beaker-core icon indicating copy to clipboard operation
beaker-core copied to clipboard

Response returned by experimental.globalFetch should have non empty`.url`

Open Gozala opened this issue 6 years ago • 1 comments

At the moment Response instance returned by experimental.globalFetch always has a url: "" which as I've encountered seems to break general assumptions around existing code bases.

Digging through the spec it does appear like there is a way to provide url of the constructed Response instance, but it's possible to do on subclass:

class MyResponse extends Response {
  constructor(url, body, init) {
    super(body, init)
    Object.defineProperty(this, 'url', {value:url, enumerable:true, configurable:true})
  }
}

Or same way on the constructed instance:

const response = new Response(body, init)
Object.defineProperty(response, 'url', {value:url, enumerable:true, configurable:true})

I would suggest doing one or the other to avoid unnecessary incompatibly with regular fetch.

Gozala avatar Nov 20 '18 06:11 Gozala

Thanks for the heads up, will do

pfrazee avatar Nov 20 '18 21:11 pfrazee