Adds support to set reactor netty websocket max frame payload length.

fixes gh-163
This commit is contained in:
Spencer Gibb
2019-03-19 13:53:27 -04:00
parent 13162fa23a
commit d817cbaeb8
3 changed files with 59 additions and 6 deletions

View File

@@ -605,8 +605,14 @@ public class GatewayAutoConfiguration {
@Bean
public ReactorNettyWebSocketClient reactorNettyWebSocketClient(
HttpClient httpClient) {
return new ReactorNettyWebSocketClient(httpClient);
HttpClientProperties properties, HttpClient httpClient) {
ReactorNettyWebSocketClient webSocketClient = new ReactorNettyWebSocketClient(
httpClient);
if (properties.getWebsocket().getMaxFramePayloadLength() != null) {
webSocketClient.setMaxFramePayloadLength(
properties.getWebsocket().getMaxFramePayloadLength());
}
return webSocketClient;
}
}

View File

@@ -57,6 +57,9 @@ public class HttpClientProperties {
/** SSL configuration for Netty HttpClient. */
private Ssl ssl = new Ssl();
/** Websocket configuration for Netty HttpClient. */
private Websocket websocket = new Websocket();
public Integer getConnectTimeout() {
return connectTimeout;
}
@@ -97,11 +100,27 @@ public class HttpClientProperties {
this.ssl = ssl;
}
public Websocket getWebsocket() {
return this.websocket;
}
public void setWebsocket(Websocket websocket) {
this.websocket = websocket;
}
@Override
public String toString() {
return new ToStringCreator(this).append("connectTimeout", connectTimeout)
.append("responseTimeout", responseTimeout).append("pool", pool)
.append("proxy", proxy).append("ssl", ssl).toString();
// @formatter:off
return new ToStringCreator(this)
.append("connectTimeout", connectTimeout)
.append("responseTimeout", responseTimeout)
.append("pool", pool)
.append("proxy", proxy)
.append("ssl", ssl)
.append("websocket", websocket)
.toString();
// @formatter:on
}
public static class Pool {
@@ -397,4 +416,25 @@ public class HttpClientProperties {
}
public class Websocket {
/** Max frame payload length. */
private Integer maxFramePayloadLength;
public Integer getMaxFramePayloadLength() {
return this.maxFramePayloadLength;
}
public void setMaxFramePayloadLength(Integer maxFramePayloadLength) {
this.maxFramePayloadLength = maxFramePayloadLength;
}
@Override
public String toString() {
return new ToStringCreator(this)
.append("maxFramePayloadLength", maxFramePayloadLength).toString();
}
}
}

View File

@@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfigurat
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient;
import static org.assertj.core.api.Assertions.assertThat;
@@ -83,7 +84,8 @@ public class GatewayAutoConfigurationTests {
"spring.cloud.gateway.httpclient.connect-timeout=10",
"spring.cloud.gateway.httpclient.response-timeout=10s",
"spring.cloud.gateway.httpclient.pool.type=fixed",
"spring.cloud.gateway.httpclient.proxy.host=myhost")
"spring.cloud.gateway.httpclient.proxy.host=myhost",
"spring.cloud.gateway.httpclient.websocket.max-frame-payload-length=1024")
.run(context -> {
assertThat(context).hasSingleBean(HttpClient.class);
HttpClient httpClient = context.getBean(HttpClient.class);
@@ -103,6 +105,11 @@ public class GatewayAutoConfigurationTests {
* assertThat(sslContext).isNotNull();
*/
// TODO: howto test SslContext
assertThat(context).hasSingleBean(ReactorNettyWebSocketClient.class);
ReactorNettyWebSocketClient webSocketClient = context
.getBean(ReactorNettyWebSocketClient.class);
assertThat(webSocketClient.getMaxFramePayloadLength())
.isEqualTo(1024);
});
}