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