Example usage for org.springframework.http HttpHeaders IF_UNMODIFIED_SINCE

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

Introduction

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

Prototype

String IF_UNMODIFIED_SINCE

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

Click Source Link

Document

The HTTP If-Unmodified-Since header field name.

Usage

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// www.  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);
        }
    }
}