Exemplo n.º 1
0
 public static Conditionals valueOf(Headers headers) {
   ImmutableList<Tag> ifMatch = makeTags(headers.getFirstHeaderValue(HeaderConstants.IF_MATCH));
   ImmutableList<Tag> ifNoneMatch =
       makeTags(headers.getFirstHeaderValue(HeaderConstants.IF_NONE_MATCH));
   DateTime modifiedSince =
       HeaderUtils.fromHttpDate(headers.getFirstHeader(HeaderConstants.IF_MODIFIED_SINCE));
   DateTime unModifiedSince =
       HeaderUtils.fromHttpDate(headers.getFirstHeader(HeaderConstants.IF_UNMODIFIED_SINCE));
   return new Conditionals(ifMatch, ifNoneMatch, modifiedSince, unModifiedSince);
 }
Exemplo n.º 2
0
  public static HTTPResponse createResponse(
      final StatusLine line, final Headers responseHeaders, final Optional<InputStream> stream) {
    Optional<String> contentLengthHeader =
        responseHeaders.getFirstHeaderValue(HeaderConstants.CONTENT_LENGTH);

    MIMEType type = responseHeaders.getContentType().orElse(MIMEType.APPLICATION_OCTET_STREAM);
    Optional<Long> length = responseHeaders.getContentLength();

    Optional<Payload> payload =
        stream
            .filter(is -> line.getStatus().isBodyContentAllowed())
            .map(is -> new InputStreamPayload(is, type, length.orElse(-1L)));

    return new HTTPResponse(payload, line, responseHeaders);
  }