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 eeb5e2c commit 0dca08a
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,17 @@ public void operationComplete(ChannelFuture future) throws Exception {
currentMessage.setTrailingHeaders(new DefaultHttpHeaders());
}

// Set the 'Content-Length' header.
currentMessage.headers().set(
HttpHeaders.Names.CONTENT_LENGTH,
String.valueOf(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 (!isContentLengthSet(currentMessage)) {
currentMessage.headers().set(
Names.CONTENT_LENGTH,
String.valueOf(content.readableBytes()));
}
// All done
out.add(currentMessage);
}
Expand Down

0 comments on commit 0dca08a

Please sign in to comment.