Search in sources :

Example 91 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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 92 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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 93 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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)

Example 94 with HttpResponse

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

the class HttpBlobHandler method prepareResponse.

private HttpResponse prepareResponse(HttpResponseStatus status) {
    HttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status);
    HttpUtil.setContentLength(response, 0);
    maybeSetConnectionCloseHeader(response);
    return response;
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Example 95 with HttpResponse

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

the class HttpBlobHandler method head.

private void head(HttpRequest request, String index, String digest) throws IOException {
    // this method only supports local mode, which is ok, since there
    // should be a redirect upfront if data is not local
    BlobShard blobShard = localBlobShard(index, digest);
    long length = blobShard.blobContainer().getFile(digest).length();
    if (length < 1) {
        simpleResponse(request, HttpResponseStatus.NOT_FOUND);
        return;
    }
    HttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
    HttpUtil.setContentLength(response, length);
    setDefaultGetHeaders(response);
    sendResponse(request, response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) BlobShard(io.crate.blob.v2.BlobShard) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)283 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)108 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)74 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)71 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 Test (org.junit.Test)60 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)57 Test (org.junit.jupiter.api.Test)56 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)54 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)51 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)47 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)42 HttpContent (io.netty.handler.codec.http.HttpContent)39 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)32 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)24 ByteBuf (io.netty.buffer.ByteBuf)20 ResponseParts (com.github.ambry.rest.NettyClient.ResponseParts)18 ChannelFuture (io.netty.channel.ChannelFuture)17 Map (java.util.Map)17 IOException (java.io.IOException)15