Correctly handle WebSockets 00 when using HttpClientCodec.
Motivation:
7995afee8f
introduced a change that broke special handling of WebSockets 00.
Modifications:
Correctly delegate to super method which has special handling for WebSockets 00.
Result:
Fixes [#7362].
This commit is contained in:
parent
756e1579b3
commit
4f4d800bbf
@ -175,7 +175,8 @@ public final class HttpClientCodec
|
|||||||
final int statusCode = ((HttpResponse) msg).getStatus().code();
|
final int statusCode = ((HttpResponse) msg).getStatus().code();
|
||||||
if (statusCode == 100 || statusCode == 101) {
|
if (statusCode == 100 || statusCode == 101) {
|
||||||
// 100-continue and 101 switching protocols response should be excluded from paired comparison.
|
// 100-continue and 101 switching protocols response should be excluded from paired comparison.
|
||||||
return true;
|
// Just delegate to super method which has all the needed handling.
|
||||||
|
return super.isContentAlwaysEmpty(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the getMethod of the HTTP request that corresponds to the
|
// Get the getMethod of the HTTP request that corresponds to the
|
||||||
@ -186,7 +187,7 @@ public final class HttpClientCodec
|
|||||||
switch (firstChar) {
|
switch (firstChar) {
|
||||||
case 'H':
|
case 'H':
|
||||||
// According to 4.3, RFC2616:
|
// According to 4.3, RFC2616:
|
||||||
// All responses to the HEAD request getMethod MUST NOT include a
|
// All responses to the HEAD request method MUST NOT include a
|
||||||
// message-body, even though the presence of entity-header fields
|
// message-body, even though the presence of entity-header fields
|
||||||
// might lead one to believe they do.
|
// might lead one to believe they do.
|
||||||
if (HttpMethod.HEAD.equals(method)) {
|
if (HttpMethod.HEAD.equals(method)) {
|
||||||
|
@ -42,12 +42,8 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
|
|
||||||
import static io.netty.util.ReferenceCountUtil.release;
|
import static io.netty.util.ReferenceCountUtil.release;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
public class HttpClientCodecTest {
|
public class HttpClientCodecTest {
|
||||||
|
|
||||||
@ -263,4 +259,28 @@ public class HttpClientCodecTest {
|
|||||||
((FullHttpResponse) finalResponse).release();
|
((FullHttpResponse) finalResponse).release();
|
||||||
assertTrue("Channel finish failed", ch.finishAndReleaseAll());
|
assertTrue("Channel finish failed", ch.finishAndReleaseAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWebSocket00Response() {
|
||||||
|
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();
|
||||||
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpClientCodec());
|
||||||
|
assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(data)));
|
||||||
|
|
||||||
|
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(false));
|
||||||
|
|
||||||
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user