@Test public void shouldNotFollowOtherCodes() { when(response.getCode()).thenReturn(202); assertThat(new FollowRedirects(client).process(null, response), is(equalTo(response))); }
public Response process(ResponseChain chain, Response response) { if (shouldRedirect(response)) { String uri = response.getHeader("Location").get(0); Request request = response.getRequest(); if (uri.charAt(0) == '/') { URI target = request.getURI().resolve(uri); return client.at(target).addHeaders(request.getHeaders()).get(); } return client.at(uri).addHeaders(request.getHeaders()).get(); } return response; }
FollowRedirects implements ResponseFeature { public Response process(ResponseChain chain, Response response) { if (shouldRedirect(response)) { String uri = response.getHeader("Location").get(0); Request request = response.getRequest(); if (uri.charAt(0) == '/') { URI target = request.getURI().resolve(uri); return client.at(target).addHeaders(request.getHeaders()).get(); } return client.at(uri).addHeaders(request.getHeaders()).get(); } return response; } }
FollowRedirects implements ResponseFeature { public Response process(ResponseChain chain, Response response) { if (shouldRedirect(response)) { String uri = response.getHeader("Location").get(0); Request request = response.getRequest(); if (uri.charAt(0) == '/') { URI target = request.getURI().resolve(uri); return client.at(target).addHeaders(request.getHeaders()).get(); } return client.at(uri).addHeaders(request.getHeaders()).get(); } return response; } FollowRedirects(RestClient client); }
FollowRedirects implements ResponseFeature { public Response process(ResponseChain chain, Response response) { if (shouldRedirect(response)) { String uri = response.getHeader("Location").get(0); Request request = response.getRequest(); if (uri.charAt(0) == '/') { URI target = request.getURI().resolve(uri); return client.at(target).addHeaders(request.getHeaders()).get(); } return client.at(uri).addHeaders(request.getHeaders()).get(); } return response; } FollowRedirects(RestClient client); Response process(ResponseChain chain, Response response); }
FollowRedirects implements ResponseFeature { public Response process(ResponseChain chain, Response response) { if (shouldRedirect(response)) { String uri = response.getHeader("Location").get(0); Request request = response.getRequest(); if (uri.charAt(0) == '/') { URI target = request.getURI().resolve(uri); return client.at(target).addHeaders(request.getHeaders()).get(); } return client.at(uri).addHeaders(request.getHeaders()).get(); } return response; } FollowRedirects(RestClient client); Response process(ResponseChain chain, Response response);  }