コード例 #1
0
  private Message handleRequestWithIfMatch(Request request) throws IOException {
    final Path path = Path.fromString(request.uri().getPath());
    final Resource resource = resolveResource(path);

    final String ifMatch = getOnlyElement(request.headers().get(Header.IF_MATCH));

    if (ifMatch.equals("*") || !ifMatch.equals(resource.etag())) {
      return handleRequestWithoutIfMatch(request);
    } else {
      return Response.clientErrorPreconditionFailed();
    }
  }
コード例 #2
0
  private Message handleRequestWithIfModifiedSince(final Request request) throws IOException {
    final Path path = Path.fromUri(request.uri());
    final Resource resource = resolveResource(path);

    try {
      String date = getOnlyElement(request.headers().get(IF_MODIFIED_SINCE));
      Date ifModifiedSince = new SimpleDateFormat().parse(date);
      if (!ifModifiedSince.after(new Date()) && !(resource.lastModified().after(new Date()))) {
        return redirectionNotModified();
      } else {
        return handleRequestWithoutIfModifiedSince(request);
      }
    } catch (ParseException e) {
      return handleRequestWithoutIfModifiedSince(request);
    }
  }
コード例 #3
0
  private Message handleRequestWithoutIfModifiedSince(final Request request) throws IOException {
    switch (request.method()) {
      case POST:

      case PUT:

        //		case DELETE:
        //			return delete(request);

      case GET:
      case HEAD:
        if (request.headers().containsKey(Header.ACCEPT)) {
          return handleRequestWithAccept(request);
        } else {
          return handleRequestWithoutAccept(request);
        }

      default:
        return clientErrorMethodNotAllowed();
    }
  }