private HandshakeInfo createHandshakeInfo(URI url, DefaultNegotiation negotiation) { HttpHeaders responseHeaders = negotiation.getResponseHeaders(); String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); return new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); }
private HandshakeInfo createHandshakeInfo(URI url, DefaultConfigurator configurator) { HttpHeaders responseHeaders = configurator.getResponseHeaders(); String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); return new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); }
private HandshakeInfo createHandshakeInfo(URI url, Session jettySession) { HttpHeaders headers = new HttpHeaders(); jettySession.getUpgradeResponse().getHeaders().forEach(headers::put); String protocol = headers.getFirst("Sec-WebSocket-Protocol"); return new HandshakeInfo(url, headers, Mono.empty(), protocol); }
private HandshakeInfo createHandshakeInfo(ServerWebExchange exchange, ServerHttpRequest request, @Nullable String protocol, Map<String, Object> attributes) { URI uri = request.getURI(); // Copy request headers, as they might be pooled and recycled by // the server implementation once the handshake HTTP exchange is done. HttpHeaders headers = new HttpHeaders(); headers.addAll(request.getHeaders()); Mono<Principal> principal = exchange.getPrincipal(); String logPrefix = exchange.getLogPrefix(); InetSocketAddress remoteAddress = request.getRemoteAddress(); return new HandshakeInfo(uri, headers, principal, protocol, remoteAddress, attributes, logPrefix); }
@Override public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) { return getHttpClient() .headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders)) .websocket(StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols())) .uri(url.toString()) .handle((inbound, outbound) -> { HttpHeaders responseHeaders = toHttpHeaders(inbound); String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); NettyDataBufferFactory factory = new NettyDataBufferFactory(outbound.alloc()); WebSocketSession session = new ReactorNettyWebSocketSession(inbound, outbound, info, factory); if (logger.isDebugEnabled()) { logger.debug("Started session '" + session.getId() + "' for " + url); } return handler.handle(session); }) .doOnRequest(n -> { if (logger.isDebugEnabled()) { logger.debug("Connecting to " + url); } }) .next(); }
protected HandshakeInfo afterHandshake(URI url, HttpHeaders responseHeaders) { if (logger.isDebugEnabled()) { logger.debug("Handshake response: " + url + ", " + responseHeaders); } String protocol = responseHeaders.getFirst(SEC_WEBSOCKET_PROTOCOL); return new HandshakeInfo(url, responseHeaders, Mono.empty(), Optional.ofNullable(protocol)); }
private HandshakeInfo getHandshakeInfo(ServerWebExchange exchange, Optional<String> protocol) { ServerHttpRequest request = exchange.getRequest(); Mono<Principal> principal = exchange.getPrincipal(); return new HandshakeInfo(request.getURI(), request.getHeaders(), principal, protocol); }
private HandshakeInfo getHandshakeInfo(ServerWebExchange exchange, Optional<String> protocol) { ServerHttpRequest request = exchange.getRequest(); Mono<Principal> principal = exchange.getPrincipal(); return new HandshakeInfo(request.getURI(), request.getHeaders(), principal, protocol); }
private HandshakeInfo getHandshakeInfo(ServerWebExchange exchange, Optional<String> protocol) { ServerHttpRequest request = exchange.getRequest(); Mono<Principal> principal = exchange.getPrincipal(); return new HandshakeInfo(request.getURI(), request.getHeaders(), principal, protocol); }
private HandshakeInfo getHandshakeInfo(ServerWebExchange exchange, Optional<String> protocol) { ServerHttpRequest request = exchange.getRequest(); Mono<Principal> principal = exchange.getPrincipal(); return new HandshakeInfo(request.getURI(), request.getHeaders(), principal, protocol); }
@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(); }