Skip to content

Commit

Permalink
Merge #2495 into 2.0.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Sep 21, 2022
2 parents c82ca20 + 6d0c5f0 commit ab977d7
Showing 1 changed file with 7 additions and 8 deletions.
Expand Up @@ -626,7 +626,7 @@ protected void onOutboundComplete() {
f = channel().writeAndFlush(newFullBodyMessage(channel().bufferAllocator().allocate(0)));
}
else if (markSentBody()) {
LastHttpContent<?> lastHttpContent = new EmptyLastHttpContent(channel().bufferAllocator());
HttpHeaders trailerHeaders = null;
// https://datatracker.ietf.org/doc/html/rfc7230#section-4.1.2
// A trailer allows the sender to include additional fields at the end
// of a chunked message in order to supply metadata that might be
Expand All @@ -642,22 +642,21 @@ else if (markSentBody()) {
// which fields will be present in the trailers.
CharSequence declaredHeaderNames = responseHeaders.get(HttpHeaderNames.TRAILER);
if (declaredHeaderNames != null) {
HttpHeaders trailerHeaders = new TrailerHeaders(declaredHeaderNames.toString());
trailerHeaders = new TrailerHeaders(declaredHeaderNames.toString());
try {
trailerHeadersConsumer.accept(trailerHeaders);
}
catch (IllegalArgumentException e) {
// A sender MUST NOT generate a trailer when header names are
// HttpServerOperations.TrailerHeaders.DISALLOWED_TRAILER_HEADER_NAMES
log.error(format(channel(), "Cannot apply trailer headers [{0}]"), declaredHeaderNames, e);
}
if (!trailerHeaders.isEmpty()) {
lastHttpContent = new DefaultLastHttpContent(channel().bufferAllocator().allocate(0));
lastHttpContent.trailingHeaders().set(trailerHeaders);
log.error(format(channel(), "Cannot apply trailer headers [{}]"), declaredHeaderNames, e);
}
}
}
f = channel().writeAndFlush(lastHttpContent);

f = channel().writeAndFlush(trailerHeaders != null && !trailerHeaders.isEmpty() ?
new DefaultLastHttpContent(channel().bufferAllocator().allocate(0), trailerHeaders) :
new EmptyLastHttpContent(channel().bufferAllocator()));
}
else {
discard();
Expand Down

0 comments on commit ab977d7

Please sign in to comment.