Skip to content

Commit

Permalink
HttpObjectAggregator only set Content-Length is not already set.
Browse files Browse the repository at this point in the history
Motivation:

HEAD requests will have a Content-Length set that doesn't match the
actual length. So we only want to set Content-Length header if it isn't
already set.

Modifications:

If check around setting the Content-Length.

Result:

A HEAD request will no correctly return the specified Content-Length
instead of the body length.
  • Loading branch information
beckje01 authored and normanmaurer committed Dec 25, 2014
1 parent 5c57b5d commit 5ba4fdf
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ protected void aggregate(FullHttpMessage aggregated, HttpContent content) throws

@Override
protected void finishAggregation(FullHttpMessage aggregated) throws Exception {
// Set the 'Content-Length' header.
aggregated.headers().set(
HttpHeaderNames.CONTENT_LENGTH,
String.valueOf(aggregated.content().readableBytes()));
// Set the 'Content-Length' header. If one isn't already set.
// This is important as HEAD responses will use a 'Content-Length' header which
// does not match the actual body, but the number of bytes that would be
// transmitted if a GET would have been used.
//
// See rfc2616 14.13 Content-Length
if (!HttpHeaderUtil.isContentLengthSet(aggregated)) {
aggregated.headers().set(
HttpHeaderNames.CONTENT_LENGTH,
String.valueOf(aggregated.content().readableBytes()));
}
}

@Override
Expand Down

0 comments on commit 5ba4fdf

Please sign in to comment.