コード例 #1
0
  private Message handleRequestWithoutRange(Request request) {
    final Path path = Path.fromUri(request.uri());
    final Resource resource = resolveResource(path);

    try {
      return Response.build(SUCCESS_OK)
          .header(CONTENT_TYPE)
          .set(APPLICATION_OCTET_STREAM.toString())
          .setBody(resource.channel());
    } catch (IOException e) {
      return serverErrorInternal();
    }
  }
コード例 #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);
    }
  }