Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2215 Do not reuse WebsocketClientSpec.Builder between Requests #2216

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,15 @@ public NettyWriteResponseFilter nettyWriteResponseFilter(GatewayProperties prope
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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;
Expand Down Expand Up @@ -210,6 +211,24 @@ public void reactorNettyRequestUpgradeStrategyWebSocketSpecBuilderIsUniquePerReq
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 {
Expand Down