use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeDataEndWithTrailers.
@Test
public void testUpgradeDataEndWithTrailers() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
LastHttpContent trailers = new DefaultLastHttpContent(hello, true);
HttpHeaders headers = trailers.trailingHeaders();
headers.set("key", "value");
assertTrue(ch.writeOutbound(trailers));
Http2DataFrame dataFrame = ch.readOutbound();
try {
assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
assertFalse(dataFrame.isEndStream());
} finally {
dataFrame.release();
}
Http2HeadersFrame headerFrame = ch.readOutbound();
assertThat(headerFrame.headers().get("key").toString(), is("value"));
assertTrue(headerFrame.isEndStream());
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeDataEnd.
@Test
public void testUpgradeDataEnd() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
LastHttpContent end = new DefaultLastHttpContent(hello, true);
assertTrue(ch.writeOutbound(end));
Http2DataFrame dataFrame = ch.readOutbound();
try {
assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
assertTrue(dataFrame.isEndStream());
} finally {
dataFrame.release();
}
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Http2ServerDowngraderTest method testDowngradeTrailers.
@Test
public void testDowngradeTrailers() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
Http2Headers headers = new DefaultHttp2Headers();
headers.set("key", "value");
assertTrue(ch.writeInbound(new DefaultHttp2HeadersFrame(headers, true)));
LastHttpContent trailers = ch.readInbound();
try {
assertThat(trailers.content().readableBytes(), is(0));
assertThat(trailers.trailingHeaders().get("key").toString(), is("value"));
assertFalse(trailers instanceof FullHttpRequest);
} finally {
trailers.release();
}
assertThat(ch.readInbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeEmptyFullResponseWithTrailers.
@Test
public void testUpgradeEmptyFullResponseWithTrailers() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
HttpHeaders trailers = response.trailingHeaders();
trailers.set("key", "value");
assertTrue(ch.writeOutbound(response));
Http2HeadersFrame headersFrame = ch.readOutbound();
assertThat(headersFrame.headers().status().toString(), is("200"));
assertFalse(headersFrame.isEndStream());
Http2HeadersFrame trailersFrame = ch.readOutbound();
assertThat(trailersFrame.headers().get("key").toString(), is("value"));
assertTrue(trailersFrame.isEndStream());
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class HAProxyMessageDecoderTest method testV2HeaderTooLong.
@Test(expected = HAProxyProtocolException.class)
public void testV2HeaderTooLong() {
ch = new EmbeddedChannel(new HAProxyMessageDecoder(0));
byte[] header = new byte[248];
// Binary Prefix
header[0] = 0x0D;
// -----
header[1] = 0x0A;
// -----
header[2] = 0x0D;
// -----
header[3] = 0x0A;
// -----
header[4] = 0x00;
// -----
header[5] = 0x0D;
// -----
header[6] = 0x0A;
// -----
header[7] = 0x51;
// -----
header[8] = 0x55;
// -----
header[9] = 0x49;
// -----
header[10] = 0x54;
// -----
header[11] = 0x0A;
// v2, cmd=PROXY
header[12] = 0x21;
// TCP over IPv4
header[13] = 0x11;
// Remaining Bytes
header[14] = 0x00;
// -----
header[15] = (byte) 0xe8;
// Source Address
header[16] = (byte) 0xc0;
// -----
header[17] = (byte) 0xa8;
// -----
header[18] = 0x00;
// -----
header[19] = 0x01;
// Destination Address
header[20] = (byte) 0xc0;
// -----
header[21] = (byte) 0xa8;
// -----
header[22] = 0x00;
// -----
header[23] = 0x0b;
// Source Port
header[24] = (byte) 0xdc;
// -----
header[25] = 0x04;
// Destination Port
header[26] = 0x01;
// -----
header[27] = (byte) 0xbb;
ch.writeInbound(copiedBuffer(header));
}
Aggregations