/// <summary> /// Handles redirect if the response's status code is redirect, redirects are turned on, and the header has /// a location. /// When the status code is <c>303</c> the method on the request is changed to a GET as per the RFC2616 /// specification. On a redirect, it also removes the <c>Authorization</c> and all <c>If-*</c> request headers. /// </summary> /// <returns> Whether this method changed the request and handled redirect successfully. </returns> private bool HandleRedirect(HttpResponseMessage message) { // TODO(peleyal): think if it's better to move that code to RedirectUnsucessfulResponseHandler var uri = message.Headers.Location; if (!message.IsRedirectStatusCode() || uri == null) { return false; } var request = message.RequestMessage; request.RequestUri = new Uri(request.RequestUri, uri); // Status code for a resource that has moved to a new URI and should be retrieved using GET. if (message.StatusCode == HttpStatusCode.SeeOther) { request.Method = HttpMethod.Get; } // Clear Authorization and If-* headers. request.Headers.Remove("Authorization"); request.Headers.IfMatch.Clear(); request.Headers.IfNoneMatch.Clear(); request.Headers.IfModifiedSince = null; request.Headers.IfUnmodifiedSince = null; request.Headers.Remove("If-Range"); return true; }