Search in sources :

Example 1 with WebSocketHandshaker

use of io.reactivex.netty.protocol.http.ws.server.WebSocketHandshaker in project spring-framework by spring-projects.

the class RxNettyRequestUpgradeStrategy method upgrade.

@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, Optional<String> subProtocol) {
    RxNettyServerHttpResponse response = (RxNettyServerHttpResponse) exchange.getResponse();
    HttpServerResponse<?> rxNettyResponse = response.getRxNettyResponse();
    HandshakeInfo info = getHandshakeInfo(exchange, subProtocol);
    NettyDataBufferFactory factory = (NettyDataBufferFactory) response.bufferFactory();
    WebSocketHandshaker handshaker = rxNettyResponse.acceptWebSocketUpgrade(conn -> {
        RxNettyWebSocketSession session = new RxNettyWebSocketSession(conn, info, factory);
        String name = HttpHandlerNames.WsServerDecoder.getName();
        session.aggregateFrames(rxNettyResponse.unsafeNettyChannel(), name);
        return RxReactiveStreams.toObservable(handler.handle(session));
    });
    if (subProtocol.isPresent()) {
        handshaker = handshaker.subprotocol(subProtocol.get());
    } else {
        // TODO: https://github.com/reactor/reactor-netty/issues/20
        handshaker = handshaker.subprotocol(new String[0]);
    }
    return Mono.from(RxReactiveStreams.toPublisher(handshaker));
}
Also used : WebSocketHandshaker(io.reactivex.netty.protocol.http.ws.server.WebSocketHandshaker) RxNettyServerHttpResponse(org.springframework.http.server.reactive.RxNettyServerHttpResponse) RxNettyWebSocketSession(org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo)

Aggregations

WebSocketHandshaker (io.reactivex.netty.protocol.http.ws.server.WebSocketHandshaker)1 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)1 RxNettyServerHttpResponse (org.springframework.http.server.reactive.RxNettyServerHttpResponse)1 HandshakeInfo (org.springframework.web.reactive.socket.HandshakeInfo)1 RxNettyWebSocketSession (org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession)1