[#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
be919b372e
commit
4f6ccbbb78
@ -362,8 +362,14 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UPGRADED: {
|
case UPGRADED: {
|
||||||
// Do not touch anything read - other handler will replace this codec with the upgraded protocol codec to
|
int readableBytes = actualReadableBytes();
|
||||||
// take the trafic over.
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,6 +478,33 @@ public class HttpResponseDecoderTest {
|
|||||||
assertThat(ch.readInbound(), is(nullValue()));
|
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
|
@Test
|
||||||
public void testGarbageHeaders() {
|
public void testGarbageHeaders() {
|
||||||
// A response without headers - from https://github.com/netty/netty/issues/2103
|
// A response without headers - from https://github.com/netty/netty/issues/2103
|
||||||
|
Loading…
x
Reference in New Issue
Block a user