private boolean isValidResponse(final Response response) { return response.getStatus().isSuccessful() || response.getAttributes().contains(USE_DISPATCHED_RESPONSE); } }
private boolean isSuccessfulOrNotModified(final Response response) { return response.getStatus().isSuccessful() || response.getStatus().getCode() == 304; }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { String path = context.getRequest().getPath(); // sanity, to ensure we don't corrupt the path if (!path.endsWith("/")) { path = path + "/"; } for (String file : INDEX_FILES) { Response response = forward(context, path + file); // return response if it was successful or an error which was not not found if (response.getStatus().isSuccessful() || response.getStatus().getCode() != HttpStatus.NOT_FOUND) { return response; } // otherwise try next index file } // or there is no such file, give up not found return HttpResponses.notFound(context.getRequest().getPath()); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = context.proceed(); Payload payload = response.getPayload(); if (response.getStatus().isSuccessful() && payload instanceof Content) { final Content content = (Content) payload; final DateTime lastModified = content.getAttributes().get(Content.CONTENT_LAST_MODIFIED, DateTime.class); if (lastModified != null) { response.getHeaders().set(HttpHeaders.LAST_MODIFIED, DateUtils.formatDate(lastModified.toDate())); } final String etag = content.getAttributes().get(Content.CONTENT_ETAG, String.class); if (etag != null) { response.getHeaders().set(HttpHeaders.ETAG, "\"" + etag + "\""); } } return response; } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { String action = context.getRequest().getAction(); if (!NFC_CACHEABLE_ACTIONS.contains(action)) { return context.proceed(); } NegativeCacheFacet negativeCache = context.getRepository().facet(NegativeCacheFacet.class); NegativeCacheKey key = negativeCache.getCacheKey(context); Response response; Status status = negativeCache.get(key); if (status == null) { response = context.proceed(); if (isNotFound(response)) { negativeCache.put(key, response.getStatus()); } else if (response.getStatus().isSuccessful()) { negativeCache.invalidate(key); } } else { response = buildResponse(status, context); log.debug("Found {} in negative cache, returning {}", key, response); } return response; }
@Override public Response handle(final Context context) throws Exception { Response response = context.proceed(); if (assetDownloadCountStore.isEnabled() && response != null && response.getStatus().isSuccessful() && isGetRequest(context.getRequest())) { Asset asset = getAssetFromPayload(response.getPayload()); if (asset != null) { assetDownloadCountStore.incrementCount(context.getRepository().getName(), asset.name()); } } return response; }
case HEAD: { final Response response = context.proceed(); if (response.getStatus().isSuccessful() && !requestPredicate.apply(response)) { final Request getRequest = new Request.Builder().copy(context.getRequest()).action(GET).build(); final Response response = context.getRepository().facet(ViewFacet.class).dispatch(getRequest); if (response.getStatus().isSuccessful() && !requestPredicate.apply(response)) {