@Test public void ifUnmodifySince_NotAccept() throws Exception { ZonedDateTime modified = ZonedDateTime.now(); RequestHeaders req = mock(RequestHeaders.class); Mockito.doReturn(Optional.of(modified.minusSeconds(60))).when(req).ifUnmodifiedSince(); Mockito.doReturn(Optional.empty()).when(req).ifModifiedSince(); ResponseHeaders res = mock(ResponseHeaders.class); assertHttpException(() -> StaticContentHandler.processModifyHeaders(modified.toInstant(), req, res), Http.Status.PRECONDITION_FAILED_412); }
static void processModifyHeaders(Instant modified, RequestHeaders requestHeaders, ResponseHeaders responseHeaders) { if (modified == null) { return; } responseHeaders.lastModified(modified); Optional<Instant> ifModSince = requestHeaders .ifModifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifModSince.isPresent() && !ifModSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Modified-Since header!", Http.Status.NOT_MODIFIED_304); } Optional<Instant> ifUnmodSince = requestHeaders .ifUnmodifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifUnmodSince.isPresent() && ifUnmodSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Unmodified-Since header!", Http.Status.PRECONDITION_FAILED_412); } }
StaticContentHandler { static void processModifyHeaders(Instant modified, RequestHeaders requestHeaders, ResponseHeaders responseHeaders) { if (modified == null) { return; } responseHeaders.lastModified(modified); Optional<Instant> ifModSince = requestHeaders .ifModifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifModSince.isPresent() && !ifModSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Modified-Since header!", Http.Status.NOT_MODIFIED_304); } Optional<Instant> ifUnmodSince = requestHeaders .ifUnmodifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifUnmodSince.isPresent() && ifUnmodSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Unmodified-Since header!", Http.Status.PRECONDITION_FAILED_412); } } }
StaticContentHandler { static void processModifyHeaders(Instant modified, RequestHeaders requestHeaders, ResponseHeaders responseHeaders) { if (modified == null) { return; } responseHeaders.lastModified(modified); Optional<Instant> ifModSince = requestHeaders .ifModifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifModSince.isPresent() && !ifModSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Modified-Since header!", Http.Status.NOT_MODIFIED_304); } Optional<Instant> ifUnmodSince = requestHeaders .ifUnmodifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifUnmodSince.isPresent() && ifUnmodSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Unmodified-Since header!", Http.Status.PRECONDITION_FAILED_412); } } StaticContentHandler(String welcomeFilename, ContentTypeSelector contentTypeSelector); }
StaticContentHandler { static void processModifyHeaders(Instant modified, RequestHeaders requestHeaders, ResponseHeaders responseHeaders) { if (modified == null) { return; } responseHeaders.lastModified(modified); Optional<Instant> ifModSince = requestHeaders .ifModifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifModSince.isPresent() && !ifModSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Modified-Since header!", Http.Status.NOT_MODIFIED_304); } Optional<Instant> ifUnmodSince = requestHeaders .ifUnmodifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifUnmodSince.isPresent() && ifUnmodSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Unmodified-Since header!", Http.Status.PRECONDITION_FAILED_412); } } StaticContentHandler(String welcomeFilename, ContentTypeSelector contentTypeSelector);  }
StaticContentHandler { static void processModifyHeaders(Instant modified, RequestHeaders requestHeaders, ResponseHeaders responseHeaders) { if (modified == null) { return; } responseHeaders.lastModified(modified); Optional<Instant> ifModSince = requestHeaders .ifModifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifModSince.isPresent() && !ifModSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Modified-Since header!", Http.Status.NOT_MODIFIED_304); } Optional<Instant> ifUnmodSince = requestHeaders .ifUnmodifiedSince() .map(ChronoZonedDateTime::toInstant); if (ifUnmodSince.isPresent() && ifUnmodSince.get().isBefore(modified)) { throw new HttpException("Not valid for If-Unmodified-Since header!", Http.Status.PRECONDITION_FAILED_412); } } StaticContentHandler(String welcomeFilename, ContentTypeSelector contentTypeSelector);   }