mock-xmlhttprequest icon indicating copy to clipboard operation
mock-xmlhttprequest copied to clipboard

How can responseURL be set

Open maxmil opened this issue 9 months ago • 1 comments

This may be a dumb question but in the README is says

responseUrl: the final request URL after redirects isn't automatically set. This can be emulated in a request handler.

It's not clear to me how to do this. I have a client that reads the responseURL to update the browser history. How can I provide it a responseUrl after a redirect.

Currently I'm using a mockXhr rather than a mockServer and I'm following redirects in my mock implementation but have no way of updating the final response URL.

maxmil avatar Mar 18 '25 18:03 maxmil

Hi, please check out #51 where I add a unit test to test this path. Does that help?

There weren't any before so it's at least good to test it now. It also made me realize that there's currently no convenient way to do the same with the mockServer. You'd need to access the private MockXhrRequest._responseReceiver attribute and "cast" it to a MockXhr. It should be straightforward to add an api, but let's see if anyone requests this feature before I work on that.

berniegp avatar Mar 23 '25 20:03 berniegp