oxsean commented on code in PR #15019:
URL: https://github.com/apache/dubbo/pull/15019#discussion_r1897380860
##########
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Codec.java:
##########
@@ -80,19 +86,28 @@ private void doWriteHeader(ChannelHandlerContext ctx,
HttpMetadata msg, ChannelP
if (CollectionUtils.isNotEmpty(statusHeaders)) {
status =
HttpResponseStatus.valueOf(Integer.parseInt(statusHeaders.get(0)));
}
+ if (keepAlive) {
+ headers.add(HttpHeaderNames.CONNECTION.getKey(),
String.valueOf(HttpHeaderValues.KEEP_ALIVE));
+ } else {
+ headers.add(HttpHeaderNames.CONNECTION.getKey(),
String.valueOf(HttpHeaderValues.CLOSE));
+ }
// process normal headers
- ctx.writeAndFlush(new DefaultHttpResponse(HttpVersion.HTTP_1_1,
status, headers.getHeaders()), promise);
+ ctx.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, status,
headers.getHeaders()), promise);
}
private void doWriteMessage(ChannelHandlerContext ctx, HttpOutputMessage
msg, ChannelPromise promise) {
if (HttpOutputMessage.EMPTY_MESSAGE == msg) {
- ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, promise);
+ if (!keepAlive) {
Review Comment:
Not flipping the boolean will make the code better understood:
```java
if (keepAlive) {
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT,
promise);
} else {
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT,
promise).addListener(ChannelFutureListener.CLOSE);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]