public HttpUriRequest getRedirect(
            final HttpRequest request,
            final HttpResponse response,
            final HttpContext context) throws ProtocolException {
        URI uri = getLocationURI(request, response, context);
        String method = request.getRequestLine().getMethod();
        if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
            return new HttpHead(uri);
        } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
            return new HttpGet(uri);
        } else {
            int status = response.getStatusLine().getStatusCode();
            if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
                if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
                    return copyEntity(new HttpPost(uri), request);
                } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
                    return copyEntity(new HttpPut(uri), request);
                } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) {
                    return new HttpDelete(uri);
                } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) {
                    return new HttpTrace(uri);
                } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) {
                    return new HttpOptions(uri);
                } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) {
                    return copyEntity(new HttpPatch(uri), request);
                }
            }
            return new HttpGet(uri);
        }
    }