Example usage for org.springframework.http HttpHeaders IF_MATCH

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

Introduction

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

Prototype

String IF_MATCH

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

Click Source Link

Document

The HTTP If-Match header field name.

Usage

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

/**
 * Check if the if-match condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param etag ETag of the entity//  w w w. j  a  va2s .  co m
 */
private void checkIfMatch(HttpServletRequest request, String etag) {
    String headerValue = request.getHeader(HttpHeaders.IF_MATCH);
    if (headerValue != null && headerValue.indexOf('*') == -1 && !anyMatches(headerValue, etag)) {
        // If none of the given ETags match, 412 Precodition failed is
        // sent back
        throw new UncheckException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
}

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

/**
 * Check if the if-unmodified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param attr File attributes/*w  w w  .ja  v  a  2  s  .  c o  m*/
 */
private void checkIfUnmodifiedSince(HttpServletRequest request, BasicFileAttributes attr) {
    if (request.getHeader(HttpHeaders.IF_MATCH) == null) {
        try {
            long lastModified = attr.lastModifiedTime().toMillis();
            long headerValue = request.getDateHeader(HttpHeaders.IF_UNMODIFIED_SINCE);
            if (headerValue != -1 && lastModified >= 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_PRECONDITION_FAILED);
            }
        } catch (IllegalArgumentException ex) {
            throw new UncheckException(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
    }
}