Search in sources :

Example 16 with FullHttpResponse

use of io.netty.handler.codec.http.FullHttpResponse in project netty by netty.

the class WebSocketServerProtocolHandlerTest method testHttpUpgradeRequestInvalidUpgradeHeader.

@Test
public void testHttpUpgradeRequestInvalidUpgradeHeader() {
    EmbeddedChannel ch = createChannel();
    FullHttpRequest httpRequestWithEntity = new WebSocketRequestBuilder().httpVersion(HTTP_1_1).method(HttpMethod.GET).uri("/test").connection("Upgrade").version00().upgrade("BogusSocket").build();
    ch.writeInbound(httpRequestWithEntity);
    FullHttpResponse response = responses.remove();
    assertEquals(BAD_REQUEST, response.status());
    assertEquals("not a WebSocket handshake request: missing upgrade", getResponseMessage(response));
    response.release();
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) Test(org.junit.Test)

Example 17 with FullHttpResponse

use of io.netty.handler.codec.http.FullHttpResponse in project netty by netty.

the class FallbackRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest req) throws Exception {
    if (HttpUtil.is100ContinueExpected(req)) {
        ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
    }
    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(response.duplicate());
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
    response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
    response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
    ctx.write(response).addListener(ChannelFutureListener.CLOSE);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ByteBuf(io.netty.buffer.ByteBuf)

Example 18 with FullHttpResponse

use of io.netty.handler.codec.http.FullHttpResponse in project netty by netty.

the class Http2RequestHandler method handleImage.

private void handleImage(String x, String y, ChannelHandlerContext ctx, String streamId, int latency, FullHttpRequest request) {
    ByteBuf image = ImageCache.INSTANCE.image(parseInt(x), parseInt(y));
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, image.duplicate());
    response.headers().set(CONTENT_TYPE, "image/jpeg");
    sendResponse(ctx, streamId, latency, response, request);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ByteBuf(io.netty.buffer.ByteBuf)

Example 19 with FullHttpResponse

use of io.netty.handler.codec.http.FullHttpResponse in project netty by netty.

the class Http2RequestHandler method sendBadRequest.

private void sendBadRequest(ChannelHandlerContext ctx, String streamId) {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST, EMPTY_BUFFER);
    streamId(response, streamId);
    ctx.writeAndFlush(response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Example 20 with FullHttpResponse

use of io.netty.handler.codec.http.FullHttpResponse in project netty by netty.

the class HttpSnoopServerHandler method send100Continue.

private static void send100Continue(ChannelHandlerContext ctx) {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, CONTINUE);
    ctx.write(response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Aggregations

FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)83 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)50 ByteBuf (io.netty.buffer.ByteBuf)24 Test (org.junit.Test)16 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)11 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)11 TransportAddress (org.elasticsearch.common.transport.TransportAddress)8 HttpServerTransport (org.elasticsearch.http.HttpServerTransport)8 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)7 HttpRequest (io.netty.handler.codec.http.HttpRequest)6 ChannelFuture (io.netty.channel.ChannelFuture)5 ChannelPipeline (io.netty.channel.ChannelPipeline)5 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)5 HashMap (java.util.HashMap)5 Channel (com.weibo.api.motan.transport.Channel)4 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 Map (java.util.Map)4 Pair (com.nike.internal.util.Pair)3