Пример #1
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);
  }