HttpObjectAggregator only set Content-Length is not already set.
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.
This commit is contained in:
parent
5c57b5de5b
commit
5ba4fdf3ba
@ -140,10 +140,17 @@ public class HttpObjectAggregator
|
||||
|
||||
@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
|
||||
|
Loading…
Reference in New Issue
Block a user