use of io.undertow.websockets.core.protocol.version13.Hybi13Handshake in project spring-framework by spring-projects.
the class UndertowRequestUpgradeStrategy method upgrade.
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, Optional<String> subProtocol) {
ServerHttpRequest request = exchange.getRequest();
Assert.isInstanceOf(UndertowServerHttpRequest.class, request, "UndertowServerHttpRequest required");
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();
}
use of io.undertow.websockets.core.protocol.version13.Hybi13Handshake in project spring-framework by spring-projects.
the class UndertowRequestUpgradeStrategy method upgrade.
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
HttpServerExchange httpExchange = ServerHttpRequestDecorator.getNativeRequest(exchange.getRequest());
Set<String> protocols = (subProtocol != null ? Collections.singleton(subProtocol) : Collections.emptySet());
Hybi13Handshake handshake = new Hybi13Handshake(protocols, false);
List<Handshake> handshakes = Collections.singletonList(handshake);
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
// Trigger WebFlux preCommit actions and upgrade
return exchange.getResponse().setComplete().then(Mono.deferContextual(contextView -> {
DefaultCallback callback = new DefaultCallback(handshakeInfo, ContextWebSocketHandler.decorate(handler, contextView), bufferFactory);
try {
new WebSocketProtocolHandshakeHandler(handshakes, callback).handleRequest(httpExchange);
} catch (Exception ex) {
return Mono.error(ex);
}
return Mono.empty();
}));
}
use of io.undertow.websockets.core.protocol.version13.Hybi13Handshake in project undertow by undertow-io.
the class WebSocketServlet method handshakes.
protected List<Handshake> handshakes() {
List<Handshake> handshakes = new ArrayList<>();
handshakes.add(new Hybi13Handshake());
handshakes.add(new Hybi08Handshake());
handshakes.add(new Hybi07Handshake());
return handshakes;
}
Aggregations