Skip to content

Commit baa7e2e

Browse files
committed
Merge pull request #22367 from envious/adding-maxframebuffersize
2 parents 2b4cd5c + 2d4247b commit baa7e2e

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
import org.springframework.web.reactive.socket.HandshakeInfo;
3232
import org.springframework.web.reactive.socket.WebSocketHandler;
3333
import org.springframework.web.reactive.socket.WebSocketSession;
34+
import org.springframework.web.reactive.socket.adapter.NettyWebSocketSessionSupport;
3435
import org.springframework.web.reactive.socket.adapter.ReactorNettyWebSocketSession;
3536

3637
/**
@@ -43,6 +44,7 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
4344

4445
private static final Log logger = LogFactory.getLog(ReactorNettyWebSocketClient.class);
4546

47+
private int maxFramePayloadLength = NettyWebSocketSessionSupport.DEFAULT_FRAME_MAX_SIZE;
4648

4749
private final HttpClient httpClient;
4850

@@ -63,14 +65,36 @@ public ReactorNettyWebSocketClient(HttpClient httpClient) {
6365
this.httpClient = httpClient;
6466
}
6567

66-
6768
/**
6869
* Return the configured {@link HttpClient}.
6970
*/
7071
public HttpClient getHttpClient() {
7172
return this.httpClient;
7273
}
7374

75+
/**
76+
* Configure the maximum allowable frame payload length. Setting this value
77+
* to your application's requirement may reduce denial of service attacks
78+
* using long data frames.
79+
* <p>Corresponds to the argument with the same name in the constructor of
80+
* {@link io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory
81+
* WebSocketServerHandshakerFactory} in Netty.
82+
* <p>By default set to 65536 (64K).
83+
* @param maxFramePayloadLength the max length for frames.
84+
* @since 5.2
85+
*/
86+
public void setMaxFramePayloadLength(int maxFramePayloadLength) {
87+
this.maxFramePayloadLength = maxFramePayloadLength;
88+
}
89+
90+
/**
91+
* Return the configured {@link #setMaxFramePayloadLength(int) maxFramePayloadLength}.
92+
* @since 5.2
93+
*/
94+
public int getMaxFramePayloadLength() {
95+
return maxFramePayloadLength;
96+
}
97+
7498

7599
@Override
76100
public Mono<Void> execute(URI url, WebSocketHandler handler) {
@@ -79,9 +103,10 @@ public Mono<Void> execute(URI url, WebSocketHandler handler) {
79103

80104
@Override
81105
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) {
106+
String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols());
82107
return getHttpClient()
83108
.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders))
84-
.websocket(StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols()))
109+
.websocket(protocols, getMaxFramePayloadLength())
85110
.uri(url.toString())
86111
.handle((inbound, outbound) -> {
87112
HttpHeaders responseHeaders = toHttpHeaders(inbound);

0 commit comments

Comments
 (0)