Example usage for io.netty.handler.codec.http HttpHeaderValues WEBSOCKET

List of usage examples for io.netty.handler.codec.http HttpHeaderValues WEBSOCKET

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaderValues WEBSOCKET.

Prototype

AsciiString WEBSOCKET

To view the source code for io.netty.handler.codec.http HttpHeaderValues WEBSOCKET.

Click Source Link

Document

"websocket"

Usage

From source file:io.gravitee.gateway.standalone.vertx.VertxReactorHandler.java

License:Apache License

private boolean isWebSocket(HttpServerRequest httpServerRequest) {
    String connectionHeader = httpServerRequest.getHeader(HttpHeaders.CONNECTION);
    String upgradeHeader = httpServerRequest.getHeader(HttpHeaders.UPGRADE);

    return httpServerRequest.method() == HttpMethod.GET
            && HttpHeaderValues.UPGRADE.contentEqualsIgnoreCase(connectionHeader)
            && HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(upgradeHeader);
}

From source file:lee.study.handle.WebSocketServerHandler.java

License:Apache License

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;//from www .j  a  v  a 2  s . co  m
    }

    // Allow only GET methods.
    if (req.method() != GET) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
        return;
    }

    if ("/favicon.ico".equals(req.uri())) {
        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);
        sendHttpResponse(ctx, req, res);
        return;
    }

    if (HttpHeaderValues.WEBSOCKET.toString().equals(req.headers().get(HttpHeaderNames.UPGRADE))) {
        // Handshake
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
                getWebSocketLocation(req), null, true, 5 * 1024 * 1024);
        handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        } else {
            handshaker.handshake(ctx.channel(), req);
            Hero hero = new Hero();
            //
            Room.room.put(ctx, hero);
        }
    } else {
        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);
        sendHttpResponse(ctx, req, res);
        return;
    }
}

From source file:net.anyflow.menton.http.HttpRequestRouter.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
    if (HttpHeaderValues.WEBSOCKET.toString().equalsIgnoreCase(request.headers().get(HttpHeaderNames.UPGRADE))
            && HttpHeaderValues.UPGRADE.toString()
                    .equalsIgnoreCase(request.headers().get(HttpHeaderNames.CONNECTION))) {

        if (ctx.pipeline().get(WebsocketFrameHandler.class) == null) {
            logger.error("No WebSocket Handler available.");

            ctx.channel()/*w ww . j av a 2s  .  co m*/
                    .writeAndFlush(
                            new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN))
                    .addListener(ChannelFutureListener.CLOSE);
            return;
        }

        ctx.fireChannelRead(request.retain());
        return;
    }

    if (HttpUtil.is100ContinueExpected(request)) {
        ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
        return;
    }

    HttpResponse response = HttpResponse.createServerDefault(request.headers().get(HttpHeaderNames.COOKIE));

    String requestPath = new URI(request.uri()).getPath();

    if (isWebResourcePath(requestPath)) {
        handleWebResourceRequest(ctx, request, response, requestPath);
    } else {
        try {
            processRequest(ctx, request, response);
        } catch (URISyntaxException e) {
            response.setStatus(HttpResponseStatus.NOT_FOUND);
            logger.info("unexcepted URI : {}", request.uri());
        } catch (Exception e) {
            response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
            logger.error("Unknown exception was thrown in business logic handler.\r\n" + e.getMessage(), e);
        }
    }
}

From source file:reactor.ipc.netty.http.server.HttpServerOperations.java

License:Open Source License

@Override
public boolean isWebsocket() {
    return requestHeaders().contains(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET, true);
}