Do not reuse WebsocketClientSpec.Builder between Requests (#2216)
This commit is contained in:
@@ -779,12 +779,15 @@ public class GatewayAutoConfiguration {
|
||||
@ConditionalOnEnabledGlobalFilter(WebsocketRoutingFilter.class)
|
||||
public ReactorNettyWebSocketClient reactorNettyWebSocketClient(HttpClientProperties properties,
|
||||
HttpClient httpClient) {
|
||||
WebsocketClientSpec.Builder builder = WebsocketClientSpec.builder()
|
||||
.handlePing(properties.getWebsocket().isProxyPing());
|
||||
if (properties.getWebsocket().getMaxFramePayloadLength() != null) {
|
||||
builder.maxFramePayloadLength(properties.getWebsocket().getMaxFramePayloadLength());
|
||||
}
|
||||
return new ReactorNettyWebSocketClient(httpClient, builder);
|
||||
Supplier<WebsocketClientSpec.Builder> builderSupplier = () -> {
|
||||
WebsocketClientSpec.Builder builder = WebsocketClientSpec.builder()
|
||||
.handlePing(properties.getWebsocket().isProxyPing());
|
||||
if (properties.getWebsocket().getMaxFramePayloadLength() != null) {
|
||||
builder.maxFramePayloadLength(properties.getWebsocket().getMaxFramePayloadLength());
|
||||
}
|
||||
return builder;
|
||||
};
|
||||
return new ReactorNettyWebSocketClient(httpClient, builderSupplier);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.netty.http.client.WebsocketClientSpec;
|
||||
import reactor.netty.http.server.WebsocketServerSpec;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -210,6 +211,24 @@ public class GatewayAutoConfigurationTests {
|
||||
assertThat(spec2.protocols()).isNull();
|
||||
}
|
||||
|
||||
|
||||
@Test // gh-2215
|
||||
public void webSocketClientSpecBuilderIsUniquePerReactorNettyWebSocketClient()
|
||||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
ReactorNettyWebSocketClient websocketClient = new GatewayAutoConfiguration.NettyConfiguration()
|
||||
.reactorNettyWebSocketClient(new HttpClientProperties(), HttpClient.create());
|
||||
|
||||
// Method "buildSpec" has only private visibility
|
||||
Method buildSpec = ReactorNettyWebSocketClient.class.getDeclaredMethod("buildSpec", String.class);
|
||||
buildSpec.setAccessible(true);
|
||||
WebsocketClientSpec spec1 = (WebsocketClientSpec) buildSpec.invoke(websocketClient, "p1");
|
||||
WebsocketClientSpec spec2 = websocketClient.getWebsocketClientSpec();
|
||||
|
||||
assertThat(spec1.protocols()).isEqualTo("p1");
|
||||
// Protocols should not be cached between requests:
|
||||
assertThat(spec2.protocols()).isNull();
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootConfiguration
|
||||
protected static class Config {
|
||||
|
||||
Reference in New Issue
Block a user