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

Do not reuse WebsocketServerSpec.Builder between requests for #2159 #2160

Closed
wants to merge 1 commit into from
Closed
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 @@ -20,6 +20,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.SslContextBuilder;
Expand Down Expand Up @@ -789,13 +790,16 @@ public ReactorNettyWebSocketClient reactorNettyWebSocketClient(HttpClientPropert
public ReactorNettyRequestUpgradeStrategy reactorNettyRequestUpgradeStrategy(
HttpClientProperties httpClientProperties) {

WebsocketServerSpec.Builder builder = WebsocketServerSpec.builder();
HttpClientProperties.Websocket websocket = httpClientProperties.getWebsocket();
PropertyMapper map = PropertyMapper.get();
map.from(websocket::getMaxFramePayloadLength).whenNonNull().to(builder::maxFramePayloadLength);
map.from(websocket::isProxyPing).to(builder::handlePing);
Supplier<WebsocketServerSpec.Builder> builderSupplier = () -> {
WebsocketServerSpec.Builder builder = WebsocketServerSpec.builder();
HttpClientProperties.Websocket websocket = httpClientProperties.getWebsocket();
PropertyMapper map = PropertyMapper.get();
map.from(websocket::getMaxFramePayloadLength).whenNonNull().to(builder::maxFramePayloadLength);
map.from(websocket::isProxyPing).to(builder::handlePing);
return builder;
};

return new ReactorNettyRequestUpgradeStrategy(builder);
return new ReactorNettyRequestUpgradeStrategy(builderSupplier);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package org.springframework.cloud.gateway.config;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Test;
import reactor.netty.http.client.HttpClient;
import reactor.netty.http.server.WebsocketServerSpec;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
Expand Down Expand Up @@ -152,6 +155,22 @@ public void verboseActuatorDisabled() {
}
}

@Test // gh-2159
public void reactorNettyRequestUpgradeStrategyWebSocketSpecBuilderIsUniquePerRequest()
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
ReactorNettyRequestUpgradeStrategy strategy = new GatewayAutoConfiguration.NettyConfiguration()
.reactorNettyRequestUpgradeStrategy(new HttpClientProperties());

// Method "buildSpec" was introduced for Tests, but has only default visiblity
Method buildSpec = ReactorNettyRequestUpgradeStrategy.class.getDeclaredMethod("buildSpec", String.class);
buildSpec.setAccessible(true);
WebsocketServerSpec spec1 = (WebsocketServerSpec) buildSpec.invoke(strategy, "p1");
WebsocketServerSpec spec2 = strategy.getWebsocketServerSpec();

assertThat(spec1.protocols()).isEqualTo("p1");
assertThat(spec2.protocols()).isNull();
}

@Test
public void tokenRelayBeansAreCreated() {
new ReactiveWebApplicationContextRunner()
Expand Down