@Test public void shouldFollowRelativeLocations() throws URISyntaxException { String uri = "/client"; when(response.getCode()).thenReturn(302); when(response.getHeader("Location")).thenReturn(Arrays.asList(uri)); when(response.getRequest()).thenReturn(oldRequest); when(oldRequest.getURI()).thenReturn(new URI("http: when(client.at(new URI("http: when(request.get()).thenReturn(redirectResponse); when(request.addHeaders(anyMap())).thenReturn(request); when(response.getRequest()).thenReturn(oldRequest); assertThat(new FollowRedirects(client).process(null, response), is(equalTo(redirectResponse))); }
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);  }