Browse Source

Merge branch '2.2.x'

pull/2187/head
spencergibb 4 years ago
parent
commit
4d600c85c4
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 18
      spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java
  2. 22
      spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/config/GatewayAutoConfigurationTests.java

18
spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java

@ -20,6 +20,7 @@ import java.security.cert.X509Certificate; @@ -20,6 +20,7 @@ import java.security.cert.X509Certificate;
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;
@ -788,13 +789,18 @@ public class GatewayAutoConfiguration { @@ -788,13 +789,18 @@ public class GatewayAutoConfiguration {
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);
}
}

22
spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/config/GatewayAutoConfigurationTests.java

@ -16,10 +16,13 @@ @@ -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;
@ -189,6 +192,25 @@ public class GatewayAutoConfigurationTests { @@ -189,6 +192,25 @@ public class GatewayAutoConfigurationTests {
.hasMessageContaining("No TokenRelayGatewayFilterFactory bean was found. Did you include");
}
@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();
}
@EnableAutoConfiguration
@SpringBootConfiguration
protected static class Config {

Loading…
Cancel
Save