//end of switch /// <exception cref="Apache.Http.ProtocolException"></exception> public virtual URI GetLocationURI(IHttpRequest request, HttpResponse response, HttpContext context) { Args.NotNull(request, "HTTP request"); Args.NotNull(response, "HTTP response"); Args.NotNull(context, "HTTP context"); HttpClientContext clientContext = ((HttpClientContext)HttpClientContext.Adapt(context )); //get the location header to find out where to redirect to Header locationHeader = response.GetFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException("Received redirect response " + response.GetStatusLine () + " but no location header"); } string location = locationHeader.GetValue(); if (this.log.IsDebugEnabled()) { this.log.Debug("Redirect requested to location '" + location + "'"); } RequestConfig config = clientContext.GetRequestConfig(); URI uri = CreateLocationURI(location); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI try { if (!uri.IsAbsolute()) { if (!config.IsRelativeRedirectsAllowed()) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed" ); } // Adjust location URI HttpHost target = clientContext.GetTargetHost(); Asserts.NotNull(target, "Target host"); URI requestURI = new URI(request.GetRequestLine().GetUri()); URI absoluteRequestURI = URIUtils.RewriteURI(requestURI, target, false); uri = URIUtils.Resolve(absoluteRequestURI, uri); } } catch (URISyntaxException ex) { throw new ProtocolException(ex.Message, ex); } RedirectLocations redirectLocations = (RedirectLocations)clientContext.GetAttribute (HttpClientContext.RedirectLocations); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.SetAttribute(HttpClientContext.RedirectLocations, redirectLocations); } if (!config.IsCircularRedirectsAllowed()) { if (redirectLocations.Contains(uri)) { throw new CircularRedirectException("Circular redirect to '" + uri + "'"); } } redirectLocations.Add(uri); return(uri); }