.iterator().next()
);
} else {
version = Version.LATEST;
}
Resource resource = host.fetch(
request.requestUri(), request.range(), version
);
if (request.headers().containsKey(HttpHeaders.IF_NONE_MATCH)) {
final String etag = request.headers()
.get(HttpHeaders.IF_NONE_MATCH)
.iterator().next();
if (etag.equals(resource.etag())) {
throw new HttpException(HttpURLConnection.HTTP_NOT_MODIFIED);
}
}
if (request.headers().containsKey(HttpHeaders.IF_MODIFIED_SINCE)) {
final Date since = DateUtils.parseDate(
request.headers().get(HttpHeaders.IF_MODIFIED_SINCE)
.iterator().next()
);
if (resource.lastModified().before(since)) {
throw new HttpException(HttpURLConnection.HTTP_NOT_MODIFIED);
}
}
if (request.headers().containsKey(HttpHeaders.ACCEPT_ENCODING)
&& request.headers().get(HttpHeaders.ACCEPT_ENCODING)
.contains("gzip")
&& HttpThread.COMPRESSIBLE.contains(resource.contentType())) {
resource = new GzipResource(resource);
}
return resource;
}