if (from.getStatusCode() > 206)
throw new HttpException(String.format("Unhandled status code - %1$s", from));
if ("text/uri-list".equals(from.getFirstHeaderOrNull(CONTENT_TYPE))) {
try {
if (from.getPayload().getInput() == null)
throw new HttpResponseException("no content", null, from);
String toParse = Strings2.toString(from.getPayload());
return URI.create(toParse.trim());
} catch (IOException e) {
throw new HttpResponseException("couldn't parse uri from content", null, from, e);
} finally {
releasePayload(from);
}
} else {
releasePayload(from);
String location = from.getFirstHeaderOrNull(LOCATION);
if (location == null)
location = from.getFirstHeaderOrNull("location");
if (location != null) {
URI locationUri = URI.create(location);
if (locationUri.getHost() != null)
return locationUri;
checkState(request != null, "request should have been initialized");
if (!location.startsWith("/"))
location = "/" + location;
locationUri = URI.create(location);
return Uris.uriBuilder(request.getEndpoint()).path(locationUri.getPath()).query(locationUri.getQuery()).build();
} else {
throw new HttpResponseException("no uri in headers or content", null, from);
}
}
}