예제 #1
0
 /**
  * Copies passed in {@link Request} and but sets action to GET and removes all supported
  * conditions making the GET request "unconditional". This method must be in sync with {@link
  * #requestPredicate(Request)} and process same conditions.
  */
 @Nonnull
 public static Request copyAsUnconditionalGet(@Nonnull final Request request) {
   checkNotNull(request);
   final Request getRequest = new Request.Builder().copy(request).action(GET).build();
   getRequest.getHeaders().remove(HttpHeaders.IF_MODIFIED_SINCE);
   getRequest.getHeaders().remove(HttpHeaders.IF_UNMODIFIED_SINCE);
   getRequest.getHeaders().remove(HttpHeaders.IF_MATCH);
   getRequest.getHeaders().remove(HttpHeaders.IF_NONE_MATCH);
   return getRequest;
 }
예제 #2
0
  @Nullable
  private static Predicate<Response> ifNoneMatch(final Request request) {
    final String match = request.getHeaders().get(HttpHeaders.IF_NONE_MATCH);
    if (match != null && !"*".equals(match)) {
      return new Predicate<Response>() {
        @Override
        public boolean apply(final Response response) {
          final String etag = response.getHeaders().get(HttpHeaders.ETAG);
          if (etag != null) {
            return !match.contains(etag);
          }
          return true;
        }

        @Override
        public String toString() {
          return HttpConditions.class.getSimpleName() + ".ifNoneMatch(" + match + ")";
        }
      };
    }
    return null;
  }
예제 #3
0
  @Nullable
  private static Predicate<Response> ifModifiedSince(final Request request) {
    final DateTime date = parseDateHeader(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE));
    if (date != null) {
      return new Predicate<Response>() {
        @Override
        public boolean apply(final Response response) {
          final DateTime lastModified =
              parseDateHeader(response.getHeaders().get(HttpHeaders.LAST_MODIFIED));
          if (lastModified != null) {
            return lastModified.isAfter(date);
          }
          return true;
        }

        @Override
        public String toString() {
          return HttpConditions.class.getSimpleName() + ".ifModifiedSince(" + date + ")";
        }
      };
    }
    return null;
  }