[#2173] Fix regression that let HttpRequestDecoder fail if the websocket response and a websocketframe are send in one go
This commit is contained in:
parent
d343a258e2
commit
dddfb149a5
@ -362,8 +362,14 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
|
||||
break;
|
||||
}
|
||||
case UPGRADED: {
|
||||
// Do not touch anything read - other handler will replace this codec with the upgraded protocol codec to
|
||||
// take the trafic over.
|
||||
int readableBytes = actualReadableBytes();
|
||||
if (readableBytes > 0) {
|
||||
// Keep on consuming as otherwise we may trigger an DecoderException,
|
||||
// other handler will replace this codec with the upgraded protocol codec to
|
||||
// take the traffic over at some point then.
|
||||
// See https://github.com/netty/netty/issues/2173
|
||||
out.add(buffer.readBytes(actualReadableBytes()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -451,6 +451,33 @@ public class HttpResponseDecoderTest {
|
||||
assertThat(ch.readInbound(), is(nullValue()));
|
||||
}
|
||||
|
||||
// See https://github.com/netty/netty/issues/2173
|
||||
@Test
|
||||
public void testWebSocketResponseWithDataFollowing() {
|
||||
byte[] data = ("HTTP/1.1 101 WebSocket Protocol Handshake\r\n" +
|
||||
"Upgrade: WebSocket\r\n" +
|
||||
"Connection: Upgrade\r\n" +
|
||||
"Sec-WebSocket-Origin: http://localhost:8080\r\n" +
|
||||
"Sec-WebSocket-Location: ws://localhost/some/path\r\n" +
|
||||
"\r\n" +
|
||||
"1234567812345678").getBytes();
|
||||
byte[] otherData = {1, 2, 3, 4};
|
||||
|
||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(data, otherData));
|
||||
|
||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||
assertThat(res.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS));
|
||||
HttpContent content = (HttpContent) ch.readInbound();
|
||||
assertThat(content.content().readableBytes(), is(16));
|
||||
content.release();
|
||||
|
||||
assertThat(ch.finish(), is(true));
|
||||
|
||||
assertEquals(ch.readInbound(), Unpooled.wrappedBuffer(otherData));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGarbageHeaders() {
|
||||
// A response without headers - from https://github.com/netty/netty/issues/2103
|
||||
|
Loading…
Reference in New Issue
Block a user