commit
						19180e04d2
					
				| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2002-2019 the original author or authors.
 | 
					 * Copyright 2002-2020 the original author or authors.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 * you may not use this file except in compliance with the License.
 | 
				
			||||||
| 
						 | 
					@ -44,10 +44,13 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static final Log logger = LogFactory.getLog(ReactorNettyWebSocketClient.class);
 | 
						private static final Log logger = LogFactory.getLog(ReactorNettyWebSocketClient.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private int maxFramePayloadLength = NettyWebSocketSessionSupport.DEFAULT_FRAME_MAX_SIZE;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private final HttpClient httpClient;
 | 
						private final HttpClient httpClient;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private int maxFramePayloadLength = NettyWebSocketSessionSupport.DEFAULT_FRAME_MAX_SIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private boolean handlePing;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Default constructor.
 | 
						 * Default constructor.
 | 
				
			||||||
| 
						 | 
					@ -65,6 +68,7 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
 | 
				
			||||||
		this.httpClient = httpClient;
 | 
							this.httpClient = httpClient;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Return the configured {@link HttpClient}.
 | 
						 * Return the configured {@link HttpClient}.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -95,6 +99,28 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
 | 
				
			||||||
		return this.maxFramePayloadLength;
 | 
							return this.maxFramePayloadLength;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Configure whether to let ping frames through to be handled by the
 | 
				
			||||||
 | 
						 * {@link WebSocketHandler} given to the execute method. By default, Reactor
 | 
				
			||||||
 | 
						 * Netty automatically replies with pong frames in response to pings. This is
 | 
				
			||||||
 | 
						 * useful in a proxy for allowing ping and pong frames through.
 | 
				
			||||||
 | 
						 * <p>By default this is set to {@code false} in which case ping frames are
 | 
				
			||||||
 | 
						 * handled automatically by Reactor Netty. If set to {@code true}, ping
 | 
				
			||||||
 | 
						 * frames will be passed through to the {@link WebSocketHandler}.
 | 
				
			||||||
 | 
						 * @param handlePing whether to let Ping frames through for handling
 | 
				
			||||||
 | 
						 * @since 5.2.4
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public void setHandlePing(boolean handlePing) {
 | 
				
			||||||
 | 
							this.handlePing = handlePing;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Return the configured {@link #setHandlePing(boolean)}.
 | 
				
			||||||
 | 
						 * @since 5.2.4
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public boolean getHandlePing() {
 | 
				
			||||||
 | 
							return this.handlePing;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public Mono<Void> execute(URI url, WebSocketHandler handler) {
 | 
						public Mono<Void> execute(URI url, WebSocketHandler handler) {
 | 
				
			||||||
| 
						 | 
					@ -106,7 +132,7 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
 | 
				
			||||||
		String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols());
 | 
							String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols());
 | 
				
			||||||
		return getHttpClient()
 | 
							return getHttpClient()
 | 
				
			||||||
				.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders))
 | 
									.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders))
 | 
				
			||||||
				.websocket(protocols, getMaxFramePayloadLength())
 | 
									.websocket(protocols, getMaxFramePayloadLength(), this.handlePing)
 | 
				
			||||||
				.uri(url.toString())
 | 
									.uri(url.toString())
 | 
				
			||||||
				.handle((inbound, outbound) -> {
 | 
									.handle((inbound, outbound) -> {
 | 
				
			||||||
					HttpHeaders responseHeaders = toHttpHeaders(inbound);
 | 
										HttpHeaders responseHeaders = toHttpHeaders(inbound);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2002-2019 the original author or authors.
 | 
					 * Copyright 2002-2020 the original author or authors.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 * you may not use this file except in compliance with the License.
 | 
				
			||||||
| 
						 | 
					@ -44,6 +44,8 @@ public class ReactorNettyRequestUpgradeStrategy implements RequestUpgradeStrateg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private int maxFramePayloadLength = NettyWebSocketSessionSupport.DEFAULT_FRAME_MAX_SIZE;
 | 
						private int maxFramePayloadLength = NettyWebSocketSessionSupport.DEFAULT_FRAME_MAX_SIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private boolean handlePing = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Configure the maximum allowable frame payload length. Setting this value
 | 
						 * Configure the maximum allowable frame payload length. Setting this value
 | 
				
			||||||
| 
						 | 
					@ -68,6 +70,29 @@ public class ReactorNettyRequestUpgradeStrategy implements RequestUpgradeStrateg
 | 
				
			||||||
		return this.maxFramePayloadLength;
 | 
							return this.maxFramePayloadLength;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Configure whether to let ping frames through to be handled by the
 | 
				
			||||||
 | 
						 * {@link WebSocketHandler} given to the upgrade method. By default, Reactor
 | 
				
			||||||
 | 
						 * Netty automatically replies with pong frames in response to pings. This is
 | 
				
			||||||
 | 
						 * useful in a proxy for allowing ping and pong frames through.
 | 
				
			||||||
 | 
						 * <p>By default this is set to {@code false} in which case ping frames are
 | 
				
			||||||
 | 
						 * handled automatically by Reactor Netty. If set to {@code true}, ping
 | 
				
			||||||
 | 
						 * frames will be passed through to the {@link WebSocketHandler}.
 | 
				
			||||||
 | 
						 * @param handlePing whether to let Ping frames through for handling
 | 
				
			||||||
 | 
						 * @since 5.2.4
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public void setHandlePing(boolean handlePing) {
 | 
				
			||||||
 | 
							this.handlePing = handlePing;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Return the configured {@link #setHandlePing(boolean)}.
 | 
				
			||||||
 | 
						 * @since 5.2.4
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public boolean getHandlePing() {
 | 
				
			||||||
 | 
							return this.handlePing;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
 | 
						public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
 | 
				
			||||||
| 
						 | 
					@ -78,7 +103,7 @@ public class ReactorNettyRequestUpgradeStrategy implements RequestUpgradeStrateg
 | 
				
			||||||
		HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
 | 
							HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
 | 
				
			||||||
		NettyDataBufferFactory bufferFactory = (NettyDataBufferFactory) response.bufferFactory();
 | 
							NettyDataBufferFactory bufferFactory = (NettyDataBufferFactory) response.bufferFactory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return reactorResponse.sendWebsocket(subProtocol, this.maxFramePayloadLength,
 | 
							return reactorResponse.sendWebsocket(subProtocol, this.maxFramePayloadLength, this.handlePing,
 | 
				
			||||||
				(in, out) -> {
 | 
									(in, out) -> {
 | 
				
			||||||
					ReactorNettyWebSocketSession session =
 | 
										ReactorNettyWebSocketSession session =
 | 
				
			||||||
							new ReactorNettyWebSocketSession(
 | 
												new ReactorNettyWebSocketSession(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue