final HttpContent requestContent = ctx.getMessage();
final HttpRequestPacket request = (HttpRequestPacket) requestContent.getHttpHeader();
if (fileCache.isEnabled() && Method.GET.equals(request.getMethod())) {
final FileCacheEntry cacheEntry = fileCache.get(request);
if (cacheEntry != null) {
final HttpResponsePacket response = request.getResponse();
prepareResponse(cacheEntry, response);
if (response.getStatus() != 200) {
// The cache hit - return empty response
ctx.write(HttpContent.builder(response)
.content(Buffers.EMPTY_BUFFER)
.last(true)
.build());
return flush(ctx);
}
// check if we can send plain or compressed data back.
// depends on client request headers and file cache entry
final boolean isServeCompressed =
cacheEntry.canServeCompressed(request);
// The client doesn't have this resource cached, so
// we have to send entire payload
prepareResponseWithPayload(cacheEntry, response,
isServeCompressed);
if (cacheEntry.type != CacheType.FILE) {
// the payload is available in a ByteBuffer
final Buffer buffer = Buffers.wrap(ctx.getMemoryManager(),
cacheEntry.getByteBuffer(isServeCompressed));
ctx.write(HttpContent.builder(response)
.content(buffer)
.last(true)
.build());