Kenneth
Kenneth

Reputation: 28737

Fetch client redirect

I'm executing a fetch request with the FetchClient (through an Aurelia wrapper).

The fetch client has three modes:

Follow, Error and Manual (I'll discard error for this question)

If I use follow, the fetch client automatically follows the redirection. The problem is that my original request uses basic auth. It works for the original request, but the redirected URL fails with those basic auth credentials.

If I use the "manual" mode, it doesn't follow through, but I don't get access to the "Location" of the redirected resource and I can't get the proper URL for the redirected resource.

How can I work around this?

It would either be a mode where I get access to the complete response, or an interceptor that allows me to modify the headers before requesting the redirected resource.

Upvotes: 5

Views: 4602

Answers (1)

Alexander Taran
Alexander Taran

Reputation: 6725

You can check the url property of the response when redirected property is true

https://developer.mozilla.org/en-US/docs/Web/API/Response/url

fetch("someUrl")
.then(r=>{
  if(r.redirected){
     const redirectedToUrl = r.url
  }  
}

Upvotes: 2

Related Questions