/** * Handles the if-none-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etag The etags * @return */ public static boolean handleIfNoneMatch(final HttpServerExchange exchange, final ETag etag, boolean allowWeak) { return handleIfNoneMatch(exchange, Collections.singletonList(etag), allowWeak); }
/** * Handles the if-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etag The etags * @return */ public static boolean handleIfMatch(final HttpServerExchange exchange, final ETag etag, boolean allowWeak) { return handleIfMatch(exchange, Collections.singletonList(etag), allowWeak); }
return true; //todo: how to tell if there is a current entity for the request List<ETag> parts = parseETagList(ifMatch); for (ETag part : parts) { if (part.isWeak() && !allowWeak) {
if (!ETagUtils.handleIfMatch(exchange, etag, false)) { return false; if (!ETagUtils.handleIfNoneMatch(exchange, etag, true)) { exchange.setStatusCode(StatusCodes.NOT_MODIFIED); exchange.endExchange();
public CachedHttpRequest(final HttpServerExchange exchange) { this.path = exchange.getRequestPath(); this.etag = ETagUtils.getETag(exchange); this.contentLocation = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LOCATION); this.language = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LANGUAGE); this.contentType = exchange.getResponseHeaders().getFirst(Headers.CONTENT_TYPE); String lmString = exchange.getResponseHeaders().getFirst(Headers.LAST_MODIFIED); if (lmString == null) { this.lastModified = null; } else { this.lastModified = DateUtils.parseDate(lmString); } //the content encoding can be decided dynamically, based on the current state of the request //as the decision to compress generally depends on size and mime type final AllowedContentEncodings encoding = exchange.getAttachment(AllowedContentEncodings.ATTACHMENT_KEY); if(encoding != null) { this.contentEncoding = encoding.getCurrentContentEncoding(); } else { this.contentEncoding = exchange.getResponseHeaders().getFirst(Headers.CONTENT_ENCODING); } this.responseCode = exchange.getStatusCode(); }
if (!ETagUtils.handleIfMatch(exchange, etag, false) || !DateUtils.handleIfUnmodifiedSince(exchange, lastModified)) { exchange.setStatusCode(StatusCodes.PRECONDITION_FAILED); return; if (!ETagUtils.handleIfNoneMatch(exchange, etag, true) || !DateUtils.handleIfModifiedSince(exchange, lastModified)) { exchange.setStatusCode(StatusCodes.NOT_MODIFIED);
public CachedHttpRequest(final HttpServerExchange exchange) { this.path = exchange.getRequestPath(); this.etag = ETagUtils.getETag(exchange); this.contentLocation = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LOCATION); this.language = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LANGUAGE); this.contentType = exchange.getResponseHeaders().getFirst(Headers.CONTENT_TYPE); String lmString = exchange.getResponseHeaders().getFirst(Headers.LAST_MODIFIED); if (lmString == null) { this.lastModified = null; } else { this.lastModified = DateUtils.parseDate(lmString); } //the content encoding can be decided dynamically, based on the current state of the request //as the decision to compress generally depends on size and mime type final AllowedContentEncodings encoding = exchange.getAttachment(AllowedContentEncodings.ATTACHMENT_KEY); if(encoding != null) { this.contentEncoding = encoding.getCurrentContentEncoding(); } else { this.contentEncoding = exchange.getResponseHeaders().getFirst(Headers.CONTENT_ENCODING); } this.responseCode = exchange.getStatusCode(); }
final Date lastModified = resource.getLastModified(); if(req.getDispatcherType() != DispatcherType.INCLUDE) { if (!ETagUtils.handleIfMatch(req.getHeader(Headers.IF_MATCH_STRING), etag, false) || !DateUtils.handleIfUnmodifiedSince(req.getHeader(Headers.IF_UNMODIFIED_SINCE_STRING), lastModified)) { resp.setStatus(StatusCodes.PRECONDITION_FAILED); return; if (!ETagUtils.handleIfNoneMatch(req.getHeader(Headers.IF_NONE_MATCH_STRING), etag, true) || !DateUtils.handleIfModifiedSince(req.getHeader(Headers.IF_MODIFIED_SINCE_STRING), lastModified)) { if(req.getMethod().equals(Methods.GET_STRING) || req.getMethod().equals(Methods.HEAD_STRING)) {
/** * Handles the if-none-match header. returns true if the request should proceed, false otherwise * * @param ifNoneMatch the header * @param etag The etags * @return */ public static boolean handleIfNoneMatch(final String ifNoneMatch, final ETag etag, boolean allowWeak) { return handleIfNoneMatch(ifNoneMatch, Collections.singletonList(etag), allowWeak); }
/** * Handles the if-match header. returns true if the request should proceed, false otherwise * * @param ifMatch The if match header * @param etag The etags * @return */ public static boolean handleIfMatch(final String ifMatch, final ETag etag, boolean allowWeak) { return handleIfMatch(ifMatch, Collections.singletonList(etag), allowWeak); }
return true; List<ETag> parts = parseETagList(ifNoneMatch); for (ETag part : parts) { if (part.getTag().equals("*")) {
public CachedHttpRequest(final HttpServerExchange exchange) { this.path = exchange.getRequestPath(); this.etag = ETagUtils.getETag(exchange); this.contentLocation = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LOCATION); this.language = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LANGUAGE); this.contentType = exchange.getResponseHeaders().getFirst(Headers.CONTENT_TYPE); String lmString = exchange.getResponseHeaders().getFirst(Headers.LAST_MODIFIED); if (lmString == null) { this.lastModified = null; } else { this.lastModified = DateUtils.parseDate(lmString); } //the content encoding can be decided dynamically, based on the current state of the request //as the decision to compress generally depends on size and mime type final AllowedContentEncodings encoding = exchange.getAttachment(AllowedContentEncodings.ATTACHMENT_KEY); if(encoding != null) { this.contentEncoding = encoding.getCurrentContentEncoding(); } else { this.contentEncoding = exchange.getResponseHeaders().getFirst(Headers.CONTENT_ENCODING); } this.responseCode = exchange.getStatusCode(); }
final Date lastModified = resource.getLastModified(); if (req.getDispatcherType() != DispatcherType.INCLUDE) { if (!ETagUtils.handleIfMatch(req.getHeader(Headers.IF_MATCH_STRING), etag, false) || !DateUtils.handleIfUnmodifiedSince(req.getHeader(Headers.IF_UNMODIFIED_SINCE_STRING), lastModified)) { resp.setStatus(StatusCodes.PRECONDITION_FAILED); return; if (!ETagUtils.handleIfNoneMatch(req.getHeader(Headers.IF_NONE_MATCH_STRING), etag, true) || !DateUtils.handleIfModifiedSince(req.getHeader(Headers.IF_MODIFIED_SINCE_STRING), lastModified)) { resp.setStatus(StatusCodes.NOT_MODIFIED);
/** * Handles the if-none-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etags The etags * @return */ public static boolean handleIfNoneMatch(final HttpServerExchange exchange, final List<ETag> etags, boolean allowWeak) { return handleIfNoneMatch(exchange.getRequestHeaders().getFirst(Headers.IF_NONE_MATCH), etags, allowWeak); }
/** * Handles the if-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etags The etags * @return */ public static boolean handleIfMatch(final HttpServerExchange exchange, final List<ETag> etags, boolean allowWeak) { return handleIfMatch(exchange.getRequestHeaders().getFirst(Headers.IF_MATCH), etags, allowWeak); }
return true; //todo: how to tell if there is a current entity for the request List<ETag> parts = parseETagList(ifMatch); for (ETag part : parts) { if (part.isWeak() && !allowWeak) {
if (!ETagUtils.handleIfMatch(exchange, etag, false)) { return false; if (!ETagUtils.handleIfNoneMatch(exchange, etag, true)) { exchange.setStatusCode(StatusCodes.NOT_MODIFIED); exchange.endExchange();
if(!ETagUtils.handleIfNoneMatch(exchange, new ETag(false, etag), false)) { exchange.setStatusCode(StatusCodes.NOT_MODIFIED); return true;
/** * Handles the if-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etag The etags * @return */ public static boolean handleIfMatch(final HttpServerExchange exchange, final ETag etag, boolean allowWeak) { return handleIfMatch(exchange, Collections.singletonList(etag), allowWeak); }
return true; //todo: how to tell if there is a current entity for the request List<ETag> parts = parseETagList(ifMatch); for (ETag part : parts) { if (part.isWeak() && !allowWeak) {