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

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

Introduction

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

Prototype

AsciiString UPGRADE

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

Click Source Link

Document

"upgrade"

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: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()/*from w  w w . jav  a  2  s . c  om*/
                    .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.HttpServerRoutes.java

License:Open Source License

/**
 * Listen for WebSocket on the passed path to be used as a routing condition. Incoming
 * connections will query the internal registry to invoke the matching handlers. <p>
 * Additional regex matching is available e.g.
 * "/test/{param}". Params are resolved using {@link HttpServerRequest#param(CharSequence)}
 *
 * @param path The {@link HttpPredicate} to resolve against this
 * path, pattern matching and capture are supported
 * @param handler an handler to invoke for the given condition
 * @param protocols sub-protocol to use in WS handshake signature
 *
 * @return a new handler//from  w w w . j  a  v  a 2s. com
 */
@SuppressWarnings("unchecked")
default HttpServerRoutes ws(String path,
        BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> handler,
        String protocols) {
    Predicate<HttpServerRequest> condition = HttpPredicate.get(path);

    return route(condition, (req, resp) -> {
        if (req.requestHeaders().contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true)) {

            HttpServerOperations ops = (HttpServerOperations) req;
            return ops.withWebsocketSupport(req.uri(), protocols, handler);
        }
        return resp.sendNotFound();
    });
}