数据发送完成后再关闭连接,解决http1.0数据传输问题

master
fengfei 7 years ago
parent 1fab6118b3
commit 778b616540
  1. 5
      proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java

@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
@ -74,7 +75,9 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
String userId = proxyMessage.getUri(); String userId = proxyMessage.getUri();
Channel userChannel = ProxyChannelManager.removeUserChannel(ctx.channel(), userId); Channel userChannel = ProxyChannelManager.removeUserChannel(ctx.channel(), userId);
if (userChannel != null) { if (userChannel != null) {
userChannel.close(); // 数据发送完成后再关闭连接,解决http1.0数据传输问题
ByteBuf buf = ctx.alloc().buffer(0);
userChannel.writeAndFlush(buf).addListener(ChannelFutureListener.CLOSE);
} }
} }

Loading…
Cancel
Save