private static ResponseHeaders maybeSetEndOfStream(ResponseHeaders headers, int contentLength,
                                                       boolean isAggregatedResponse) {
        if (contentLength > 0) {
            return headers;
        }
        if (isAggregatedResponse) {
            // It is unnecessary to store endOfStream to headers for AggregatedHttpResponse since the length
            // can be computed when the headers and data are aggregated.
            return headers;
        }
        if (headers.isEndOfStream()) {
            return headers;
        }

        return headers.toBuilder()
                      .endOfStream(true)
                      .build();
    }
Returns a {@link ResponseHeaders} whose {@link HttpHeaderNames#CONTENT_LENGTH} is added or removed
according to the status of the specified {@code headers}, {@code content} and {@code trailers}.
The {@link HttpHeaderNames#CONTENT_LENGTH} is removed when:
<ul>
  <li>the status of the specified {@code headers} is one of {@link HttpStatus#NO_CONTENT},
      {@link HttpStatus#RESET_CONTENT} or {@link HttpStatus#NOT_MODIFIED}</li>
  <li>the trailers exists</li>
</ul>
The {@link HttpHeaderNames#CONTENT_LENGTH} is added when the state of the specified {@code headers}
does not meet the conditions above and {@link HttpHeaderNames#CONTENT_LENGTH} is not present
regardless of the fact that the content is empty or not.

<p>{@link ResponseHeaders#isEndOfStream()} is set to {@code true} if both {@link HttpData} and trailers
are empty.

@throws IllegalArgumentException if the specified {@code content} is not empty when the specified
                                 {@link HttpStatus} is one of {@link HttpStatus#NO_CONTENT},
                                 {@link HttpStatus#RESET_CONTENT} and {@link HttpStatus#NOT_MODIFIED}.
core/src/main/java/com/linecorp/armeria/internal/common/ArmeriaHttpUtil.java