private boolean isCacheable() { return route != null && HttpUtils.isGetReq(this) && route.cache() != null && cookies.isEmpty() && U.notEmpty(host()) && !hasToken(); }
private boolean serveFromCache(ReqImpl req) { // if the HTTP request is not cacheable, the cache key will be null HTTPCacheKey cacheKey = req.cacheKey(); Route route = req.route(); if (route != null) { Cache<HTTPCacheKey, CachedResp> cache = route.cache(); if (cache != null) { if (cacheKey != null) { CachedResp resp = cache.getIfExists(cacheKey); if (resp != null) { serveCached(req, resp); return true; } } else { cache.bypass(); // notify it's not cacheable } } } return false; }
private void saveToCache() { U.must(posBeforeBody != UNDEFINED); Buf out = channel.output(); int posAfterBody = out.size(); int bodyLength = (int) (posAfterBody - posBeforeBody); // FIXME validate '\r\n\r\n' before the start position of the response body Cache<HTTPCacheKey, CachedResp> cache = route.cache(); U.notNull(cache, "route.cache"); SimpleHttpResp proxyResp = new SimpleHttpResp(); proxyResp.cookies = U.map(U.safe(response != null ? response.cookies() : null)); Map<String, String> headers = response != null ? response.headers() : Collections.emptyMap(); HttpUtils.proxyResponseHeaders(headers, proxyResp); proxyResp.code = response != null ? response.code() : 200; if (proxyResp.contentType == null) { proxyResp.contentType = response != null ? response.contentType() : defaultContentType; } // don't cache the response if it contains cookies or token data if (U.notEmpty(proxyResp.cookies) || hasToken()) return; ByteBuffer body = writeBodyToBuf(out, bodyLength); CachedResp cached = new CachedResp(proxyResp.code, proxyResp.contentType, proxyResp.headers, body); cache.set(cacheKey, cached); }
private boolean isCacheable() { return route != null && HttpUtils.isGetReq(this) && route.cache() != null && cookies.isEmpty() && U.notEmpty(host()) && !hasToken(); }
private boolean serveFromCache(ReqImpl req) { // if the HTTP request is not cacheable, the cache key will be null HTTPCacheKey cacheKey = req.cacheKey(); Route route = req.route(); if (route != null) { Cache<HTTPCacheKey, CachedResp> cache = route.cache(); if (cache != null) { if (cacheKey != null) { CachedResp resp = cache.getIfExists(cacheKey); if (resp != null) { serveCached(req, resp); return true; } } else { cache.bypass(); // notify it's not cacheable } } } return false; }
private void saveToCache() { U.must(posBeforeBody != UNDEFINED); Buf out = channel.output(); int posAfterBody = out.size(); int bodyLength = (int) (posAfterBody - posBeforeBody); // FIXME validate '\r\n\r\n' before the start position of the response body Cache<HTTPCacheKey, CachedResp> cache = route.cache(); U.notNull(cache, "route.cache"); SimpleHttpResp proxyResp = new SimpleHttpResp(); proxyResp.cookies = U.map(U.safe(response != null ? response.cookies() : null)); Map<String, String> headers = response != null ? response.headers() : Collections.<String, String>emptyMap(); HttpUtils.proxyResponseHeaders(headers, proxyResp); proxyResp.code = response != null ? response.code() : 200; if (proxyResp.contentType == null) { proxyResp.contentType = response != null ? response.contentType() : defaultContentType; } // don't cache the response if it contains cookies or token data if (U.notEmpty(proxyResp.cookies) || hasToken()) return; ByteBuffer body = writeBodyToBuf(out, bodyLength); CachedResp cached = new CachedResp(proxyResp.code, proxyResp.contentType, proxyResp.headers, body); cache.set(cacheKey, cached); }