Upgrade connection after completed response
Channel handlers above the HttpEncoder may delay the repsonse being written to the socket. We need to wait for the response to complete before upgrading the pipeline.
This commit is contained in:
parent
37a80ddd08
commit
90d15c4627
@ -22,6 +22,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.handler.codec.http.DefaultHttpResponse;
|
import io.netty.handler.codec.http.DefaultHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpChunkAggregator;
|
import io.netty.handler.codec.http.HttpChunkAggregator;
|
||||||
@ -180,7 +181,12 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
|||||||
|
|
||||||
ChannelFuture future = channel.write(res);
|
ChannelFuture future = channel.write(res);
|
||||||
|
|
||||||
|
future.addListener(new ChannelFutureListener() {
|
||||||
|
public void operationComplete(ChannelFuture future) {
|
||||||
|
ChannelPipeline p = future.channel().pipeline();
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket00FrameEncoder());
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket00FrameEncoder());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,9 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
|||||||
ChannelFuture future = channel.write(res);
|
ChannelFuture future = channel.write(res);
|
||||||
|
|
||||||
// Upgrade the connection and send the handshake response.
|
// Upgrade the connection and send the handshake response.
|
||||||
ChannelPipeline p = channel.pipeline();
|
future.addListener(new ChannelFutureListener() {
|
||||||
|
public void operationComplete(ChannelFuture future) {
|
||||||
|
ChannelPipeline p = future.channel().pipeline();
|
||||||
if (p.get(HttpChunkAggregator.class) != null) {
|
if (p.get(HttpChunkAggregator.class) != null) {
|
||||||
p.remove(HttpChunkAggregator.class);
|
p.remove(HttpChunkAggregator.class);
|
||||||
}
|
}
|
||||||
@ -155,6 +157,8 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
|||||||
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
||||||
new WebSocket08FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket08FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket08FrameEncoder(false));
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket08FrameEncoder(false));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,9 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
|||||||
ChannelFuture future = channel.write(res);
|
ChannelFuture future = channel.write(res);
|
||||||
|
|
||||||
// Upgrade the connection and send the handshake response.
|
// Upgrade the connection and send the handshake response.
|
||||||
ChannelPipeline p = channel.pipeline();
|
future.addListener(new ChannelFutureListener() {
|
||||||
|
public void operationComplete(ChannelFuture future) {
|
||||||
|
ChannelPipeline p = future.channel().pipeline();
|
||||||
if (p.get(HttpChunkAggregator.class) != null) {
|
if (p.get(HttpChunkAggregator.class) != null) {
|
||||||
p.remove(HttpChunkAggregator.class);
|
p.remove(HttpChunkAggregator.class);
|
||||||
}
|
}
|
||||||
@ -155,6 +157,8 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
|||||||
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
||||||
new WebSocket13FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket13FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket13FrameEncoder(false));
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket13FrameEncoder(false));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user