Search in sources :

Example 56 with DefaultFullHttpResponse

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

the class HTTPDataPointDecoder method writeResponse.

private boolean writeResponse(HttpObject httpObject, ChannelHandlerContext ctx) {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, httpObject.decoderResult().isSuccess() ? OK : BAD_REQUEST, Unpooled.copiedBuffer(responseString.toString().toString(), CharsetUtil.UTF_8));
    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
    response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
    response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    responseString = new StringBuilder();
    // Write the response.
    ctx.write(response);
    return true;
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Example 57 with DefaultFullHttpResponse

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

the class HTTPDataPointDecoder 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)

Example 58 with DefaultFullHttpResponse

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

the class VMDebugServerHandler method handleHttpRequest.

private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) {
    // Handle a bad request.
    if (!req.decoderResult().isSuccess()) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
        return;
    }
    // Allow only GET methods.
    if (req.method() != GET) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
        return;
    }
    if (!DebugConstants.DEBUG_WEBSOCKET_PATH.equals(req.uri())) {
        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);
        sendHttpResponse(ctx, req, res);
        return;
    }
    // Handshake
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true);
    handshaker = wsFactory.newHandshaker(req);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
    } else {
        try {
            debugManager.addDebugSession(ctx.channel());
        } catch (DebugException e) {
            FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, TOO_MANY_REQUESTS);
            sendHttpResponse(ctx, req, res);
            return;
        }
        handshaker.handshake(ctx.channel(), req);
    }
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) WebSocketServerHandshakerFactory(io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory)

Example 59 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project modules-extra by CubeEngine.

the class HttpRequestHandler method error.

private void error(ChannelHandlerContext context, RequestStatus error, ApiRequestException e) {
    Map<String, Object> data = new HashMap<>();
    data.put("id", error.getCode());
    data.put("desc", error.getDescription());
    if (e != null) {
        Map<String, Object> reason = new HashMap<>();
        reason.put("id", e.getCode());
        reason.put("desc", e.getMessage());
        data.put("reason", reason);
    }
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, error.getRepsonseStatus(), Unpooled.copiedBuffer(this.serialize(data), this.UTF8));
    response.headers().set(CONTENT_TYPE, MimeType.JSON.toString());
    context.writeAndFlush(response).addListener(CLOSE).addListener(CLOSE_ON_FAILURE);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HashMap(java.util.HashMap) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Example 60 with DefaultFullHttpResponse

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

the class RootRedirect method processRequest.

@Override
protected boolean processRequest(FullHttpRequest request, ChannelHandlerContext ctx) throws HttpRequestFailure {
    FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.MOVED_PERMANENTLY);
    boolean keepAlive = addKeepAlive(request, response, 0);
    response.headers().set(HttpHeaderNames.LOCATION, "/static/index.html");
    ChannelFuture redirectfutur = ctx.writeAndFlush(response);
    addLogger(redirectfutur, request.method().name(), request.uri(), response.status().code(), "redirect");
    return keepAlive;
}
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)

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