}
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;
}