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