@Override public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, Optional<String> subProtocol) { ServerHttpRequest request = exchange.getRequest(); Assert.isTrue(request instanceof UndertowServerHttpRequest); HttpServerExchange httpExchange = ((UndertowServerHttpRequest) request).getUndertowExchange(); Set<String> protocols = subProtocol.map(Collections::singleton).orElse(Collections.emptySet()); Hybi13Handshake handshake = new Hybi13Handshake(protocols, false); List<Handshake> handshakes = Collections.singletonList(handshake); URI url = request.getURI(); HttpHeaders headers = request.getHeaders(); Mono<Principal> principal = exchange.getPrincipal(); HandshakeInfo info = new HandshakeInfo(url, headers, principal, subProtocol); DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory(); try { DefaultCallback callback = new DefaultCallback(info, handler, bufferFactory); new WebSocketProtocolHandshakeHandler(handshakes, callback).handleRequest(httpExchange); } catch (Exception ex) { return Mono.error(ex); } return Mono.empty(); }