use of reactor.netty.http.server.WebsocketServerSpec in project spring-framework by spring-projects.
the class ReactorNettyRequestUpgradeStrategyTests method defaultWebSocketSpecBuilderIsUniquePerRequest.
// gh-25315
@Test
void defaultWebSocketSpecBuilderIsUniquePerRequest() {
ReactorNettyRequestUpgradeStrategy strategy = new ReactorNettyRequestUpgradeStrategy();
WebsocketServerSpec spec1 = strategy.buildSpec("p1");
WebsocketServerSpec spec2 = strategy.getWebsocketServerSpec();
assertThat(spec1.protocols()).isEqualTo("p1");
assertThat(spec2.protocols()).isNull();
}
use of reactor.netty.http.server.WebsocketServerSpec in project spring-framework by spring-projects.
the class ReactorNettyRequestUpgradeStrategy method upgrade.
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
ServerHttpResponse response = exchange.getResponse();
HttpServerResponse reactorResponse = ServerHttpResponseDecorator.getNativeResponse(response);
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
NettyDataBufferFactory bufferFactory = (NettyDataBufferFactory) response.bufferFactory();
URI uri = exchange.getRequest().getURI();
// Trigger WebFlux preCommit actions and upgrade
return response.setComplete().then(Mono.defer(() -> {
WebsocketServerSpec spec = buildSpec(subProtocol);
return reactorResponse.sendWebsocket((in, out) -> {
ReactorNettyWebSocketSession session = new ReactorNettyWebSocketSession(in, out, handshakeInfo, bufferFactory, spec.maxFramePayloadLength());
return handler.handle(session).checkpoint(uri + " [ReactorNettyRequestUpgradeStrategy]");
}, spec);
}));
}
Aggregations