jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

Proxy using fetch under the hood? #78

Open tom-drake opened 5 years ago

tom-drake commented 5 years ago

I noticed that if a request is proxied it is done as a fetch rather than an XHR. Would it make sense just to use the RealXMLHttpRequest rather than 'http' and 'https'?

jameslnewell commented 5 years ago

Yep sounds reasonable. From memory, because we've replaced the global XMLHttpRequest, we don't have access to the real XMLHttpRequest within a handler so using fetch was a hack to send real requests instead of mock ones.

In v3 the handler will receive a context object that we can put the real XMLHttpRequest on.

tom-drake commented 5 years ago

If this is going into a future version then great. I worked around this by creating my own proxy that makes use of XHRMock.RealXMLHttpRequest which seems to give me access to the real one before being overridden.