-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust Content-Length header when encoding Full Responses #6809
Conversation
@@ -205,6 +208,25 @@ protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> ou | |||
} | |||
} | |||
|
|||
private void encodeFullResponse(HttpResponse newRes, HttpContent content, List<Object> out) { | |||
int existingMessages = out.size(); | |||
assert encodeContent(content, out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in runtime an assert
block is ignoring if -ea
option has not specified.
@@ -205,6 +208,25 @@ protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> ou | |||
} | |||
} | |||
|
|||
private void encodeFullResponse(HttpResponse newRes, HttpContent content, List<Object> out) { | |||
int existingMessages = out.size(); | |||
assert encodeContent(content, out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want this to be an assert
, right? assert
statements can be disabled via command line and optimized away by JIT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
fullRes.headers().set(HttpHeaderNames.CONTENT_LENGTH, fullRes.content().readableBytes()); | ||
ch.writeOutbound(fullRes); | ||
|
||
Object o = ch.readOutbound(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider just directly casting to the object you expect like the other tests ... a class cast exception will be thrown if the expected type is not read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm ... @normanmaurer - wdyt?
@Scottmitch yeah LGTM... @bryce-anderson can you please squash ? After this I will pull in |
Motivation: If a full HttpResponse with a Content-Length header is encoded by the HttpContentEncoder subtypes the Content-Length header is removed and the message is set to Transfer-Encoder: chunked. This is an unnecessary loss of information about the message content. Modifications: - If a full HttpResponse has a Content-Length header, the header is adjusted after encoding. Result: Complete messages continue to have the Content-Length header after encoding.
92ae70b
to
d31fba8
Compare
Squished. Thanks for the reviews, @fenik17, @Scottmitch and @normanmaurer. |
@normanmaurer, @Scottmitch I just occurred to me: do any of the content encoders emit a raw |
Okay, looks like my worries were unfounded: all content emitted from the compressors is wrapped in |
Motivation:
If a full HttpResponse with a Content-Length header is encoded by the HttpContentEncoder subtypes the Content-Length header is removed and the message is set to Transfer-Encoder: chunked. This is an unnecessary loss of information about the message content.
Modifications:
Result:
Fixes #6808.