Example usage for org.springframework.http HttpHeaders IF_NONE_MATCH

List of usage examples for org.springframework.http HttpHeaders IF_NONE_MATCH

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders IF_NONE_MATCH.

Prototype

String IF_NONE_MATCH

To view the source code for org.springframework.http HttpHeaders IF_NONE_MATCH.

Click Source Link

Document

The HTTP If-None-Match header field name.

Usage

From source file:org.openlmis.fulfillment.service.request.RequestHeaders.java

public RequestHeaders setIfNoneMatch(String value) {
    return set(HttpHeaders.IF_NONE_MATCH, value);
}

From source file:com.github.zhanhb.ckfinder.download.PathPartial.java

/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param attr File attributes//  w ww. j a  va2s .c  o m
 */
@SuppressWarnings("NestedAssignment")
private void checkIfModifiedSince(HttpServletRequest request, BasicFileAttributes attr) {
    try {
        long headerValue;
        // If an If-None-Match header has been specified, if modified since
        // is ignored.
        if (request.getHeader(HttpHeaders.IF_NONE_MATCH) == null
                && (headerValue = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)) != -1
                && attr.lastModifiedTime().toMillis() < headerValue + 1000) {
            // The entity has not been modified since the date
            // specified by the client. This is not an error case.
            throw new UncheckException(HttpServletResponse.SC_NOT_MODIFIED);
        }
    } catch (IllegalArgumentException ex) {
    }
}

From source file:com.github.zhanhb.ckfinder.download.PathPartial.java

/**
 * Check if the if-none-match condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param etag ETag of the entity//from w ww . j a v  a 2  s.  c  o m
 */
private void checkIfNoneMatch(HttpServletRequest request, String etag) {
    String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH);
    if (headerValue != null && (headerValue.equals("*") || anyMatches(headerValue, etag))) {
        // For GET and HEAD, we should respond with
        // 304 Not Modified.
        // For every other method, 412 Precondition Failed is sent
        // back.
        String method = request.getMethod();
        if ("GET".equals(method) || "HEAD".equals(method)) {
            throw new UncheckException(HttpServletResponse.SC_NOT_MODIFIED);
        } else {
            throw new UncheckException(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
    }
}

From source file:net.turnbig.pandora.web.Servlets.java

/**
 * ?? If-None-Match Header, Etag?.//from   w  w  w. j a  v a  2 s  .  co m
 * 
 * Etag, checkIfNoneMatchfalse, 304 not modify status.
 * 
 * @param etag ETag.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH);
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!"*".equals(headerValue)) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader(HttpHeaders.ETAG, etag);
            return false;
        }
    }
    return true;
}