use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class Http2StreamFrameToHttpObjectCodecTest method testDowngradeTrailers.
@Test
public void testDowngradeTrailers() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(true));
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"), is("value"));
assertFalse(trailers instanceof FullHttpRequest);
} finally {
trailers.release();
}
assertThat(ch.readInbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class Http2StreamFrameToHttpObjectCodecTest method testDecodeResponseTrailersAsClient.
@Test
public void testDecodeResponseTrailersAsClient() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false));
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"), is("value"));
assertFalse(trailers instanceof FullHttpRequest);
} finally {
trailers.release();
}
assertThat(ch.readInbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class Http2StreamFrameToHttpObjectCodecTest method testEncodeHttpsSchemeWhenSslHandlerExists.
@Test
public void testEncodeHttpsSchemeWhenSslHandlerExists() throws Exception {
final Queue<Http2StreamFrame> frames = new ConcurrentLinkedQueue<Http2StreamFrame>();
final SslContext ctx = SslContextBuilder.forClient().sslProvider(SslProvider.JDK).build();
EmbeddedChannel ch = new EmbeddedChannel(ctx.newHandler(ByteBufAllocator.DEFAULT), new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof Http2StreamFrame) {
frames.add((Http2StreamFrame) msg);
ctx.write(Unpooled.EMPTY_BUFFER, promise);
} else {
ctx.write(msg, promise);
}
}
}, new Http2StreamFrameToHttpObjectCodec(false));
try {
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/hello/world");
assertTrue(ch.writeOutbound(req));
ch.finishAndReleaseAll();
Http2HeadersFrame headersFrame = (Http2HeadersFrame) frames.poll();
Http2Headers headers = headersFrame.headers();
assertThat(headers.scheme().toString(), is("https"));
assertThat(headers.method().toString(), is("GET"));
assertThat(headers.path().toString(), is("/hello/world"));
assertTrue(headersFrame.isEndStream());
assertNull(frames.poll());
} finally {
ch.finishAndReleaseAll();
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class HttpStaticFileServerHandler method sendAndCleanupConnection.
/**
* If Keep-Alive is disabled, attaches "Connection: close" header to the response
* and closes the connection after the response being sent.
*/
private void sendAndCleanupConnection(ChannelHandlerContext ctx, FullHttpResponse response) {
final FullHttpRequest request = this.request;
final boolean keepAlive = HttpUtil.isKeepAlive(request);
HttpUtil.setContentLength(response, response.content().readableBytes());
if (!keepAlive) {
// We're going to close the connection as soon as the response is sent,
// so we should also make it clear for the client.
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
} else if (request.protocolVersion().equals(HTTP_1_0)) {
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
ChannelFuture flushPromise = ctx.writeAndFlush(response);
if (!keepAlive) {
// Close the connection as soon as the response is sent.
flushPromise.addListener(ChannelFutureListener.CLOSE);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class WebSocketClientHandshakerTest method testUpgradeUrlWithoutPathWithQuery.
@Test
public void testUpgradeUrlWithoutPathWithQuery() {
URI uri = URI.create("ws://localhost:9999?a=b%20c");
WebSocketClientHandshaker handshaker = newHandshaker(uri);
FullHttpRequest request = handshaker.newHandshakeRequest();
try {
assertEquals("/?a=b%20c", request.uri());
} finally {
request.release();
}
}
Aggregations