Search in sources :

Example 86 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project zuul by Netflix.

the class ClientRequestReceiver method handleExpect100Continue.

private void handleExpect100Continue(ChannelHandlerContext ctx, HttpRequest req) {
    if (HttpUtil.is100ContinueExpected(req)) {
        PerfMark.event("CRR.handleExpect100Continue");
        final ChannelFuture f = ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
        f.addListener((s) -> {
            if (!s.isSuccess()) {
                throw new ZuulException(s.cause(), "Failed while writing 100-continue response", true);
            }
        });
        // Remove the Expect: 100-Continue header from request as we don't want to proxy it downstream.
        req.headers().remove(HttpHeaderNames.EXPECT);
        zuulRequest.getHeaders().remove(HttpHeaderNames.EXPECT.toString());
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ZuulException(com.netflix.zuul.exception.ZuulException)

Example 87 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project zuul by Netflix.

the class ClientResponseWriter method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    int status = 500;
    final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " + ChannelUtils.channelInfoForLogging(ctx.channel());
    if (cause instanceof ZuulException) {
        final ZuulException ze = (ZuulException) cause;
        status = ze.getStatusCode();
        LOG.error(errorMsg, cause);
    } else if (cause instanceof ReadTimeoutException) {
        LOG.error(errorMsg + ", Read timeout fired");
        status = 504;
    } else {
        LOG.error(errorMsg, cause);
    }
    if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) {
        final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status));
        ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE);
        startedSendingResponseToClient = true;
    } else {
        ctx.close();
    }
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ReadTimeoutException(io.netty.handler.timeout.ReadTimeoutException) ZuulException(com.netflix.zuul.exception.ZuulException) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Example 88 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project zuul by Netflix.

the class PushMessageSender method sendHttpResponse.

private void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest request, HttpResponseStatus status, PushUserAuth userAuth) {
    final FullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, status);
    resp.headers().add("Content-Length", "0");
    final ChannelFuture cf = ctx.channel().writeAndFlush(resp);
    if (!HttpUtil.isKeepAlive(request)) {
        cf.addListener(ChannelFutureListener.CLOSE);
    }
    logPushEvent(request, status, userAuth);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Example 89 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project vert.x by eclipse.

the class WebSocketHandshakeInboundHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof HttpResponse) {
        HttpResponse resp = (HttpResponse) msg;
        response = new DefaultFullHttpResponse(resp.protocolVersion(), resp.status());
        response.headers().add(resp.headers());
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;
        try {
            if (response != null) {
                response.content().writeBytes(content.content());
                if (msg instanceof LastHttpContent) {
                    response.trailingHeaders().add(((LastHttpContent) msg).trailingHeaders());
                    ChannelPipeline pipeline = chctx.pipeline();
                    pipeline.remove(WebSocketHandshakeInboundHandler.this);
                    ChannelHandler handler = pipeline.get(HttpContentDecompressor.class);
                    if (handler != null) {
                        // remove decompressor as its not needed anymore once connection was upgraded to WebSocket
                        ctx.pipeline().remove(handler);
                    }
                    Future<HeadersAdaptor> fut = handshakeComplete(response);
                    wsHandler.handle(fut);
                }
            }
        } finally {
            content.release();
        }
    }
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HeadersAdaptor(io.vertx.core.http.impl.headers.HeadersAdaptor) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) ChannelHandler(io.netty.channel.ChannelHandler) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 90 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project crate by crate.

the class HttpAuthUpstreamHandler method sendUnauthorized.

@VisibleForTesting
static void sendUnauthorized(Channel channel, @Nullable String body) {
    HttpResponse response;
    if (body != null) {
        if (!body.endsWith("\n")) {
            body += "\n";
        }
        response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED, copiedBuffer(body, StandardCharsets.UTF_8));
        HttpUtil.setContentLength(response, body.length());
    } else {
        response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
    }
    // "Tell" the browser to open the credentials popup
    // It helps to avoid custom login page in AdminUI
    response.headers().set(HttpHeaderNames.WWW_AUTHENTICATE, WWW_AUTHENTICATE_REALM_MESSAGE);
    channel.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Aggregations

DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)223 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)145 ByteBuf (io.netty.buffer.ByteBuf)68 HttpResponse (io.netty.handler.codec.http.HttpResponse)39 Test (org.junit.Test)25 HttpRequest (io.netty.handler.codec.http.HttpRequest)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)23 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)22 ChannelFuture (io.netty.channel.ChannelFuture)19 IOException (java.io.IOException)19 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)16 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)16 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)15 HttpObject (io.netty.handler.codec.http.HttpObject)15 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)12 HttpVersion (io.netty.handler.codec.http.HttpVersion)12 InetSocketAddress (java.net.InetSocketAddress)12 SSLException (javax.net.ssl.SSLException)12 Test (org.junit.jupiter.api.Test)12 Map (java.util.Map)11