oxsean commented on code in PR #15019:
URL: https://github.com/apache/dubbo/pull/15019#discussion_r1897380039


##########
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/netty4/h1/NettyHttp1Codec.java:
##########
@@ -31,21 +31,27 @@
 import io.netty.buffer.ByteBufInputStream;
 import io.netty.buffer.ByteBufOutputStream;
 import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelPromise;
 import io.netty.handler.codec.http.DefaultHttpResponse;
 import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpHeaderValues;
 import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpUtil;
 import io.netty.handler.codec.http.HttpVersion;
 import io.netty.handler.codec.http.LastHttpContent;
 
 public class NettyHttp1Codec extends ChannelDuplexHandler {
 
+    boolean keepAlive;

Review Comment:
   private boolean keepAlive;



##########
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:
   ···
               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]

Reply via email to