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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations