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
eeb5e2c0a9
commit
0dca08ab12
@ -212,11 +212,17 @@ public class HttpObjectAggregator extends MessageToMessageDecoder<HttpObject> {
|
|||||||
currentMessage.setTrailingHeaders(new DefaultHttpHeaders());
|
currentMessage.setTrailingHeaders(new DefaultHttpHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the 'Content-Length' header.
|
// Set the 'Content-Length' header. If one isn't already set.
|
||||||
currentMessage.headers().set(
|
// This is important as HEAD responses will use a 'Content-Length' header which
|
||||||
HttpHeaders.Names.CONTENT_LENGTH,
|
// does not match the actual body, but the number of bytes that would be
|
||||||
String.valueOf(content.readableBytes()));
|
// 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
|
// All done
|
||||||
out.add(currentMessage);
|
out.add(currentMessage);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user