Skip to content

Commit 2d4247b

Browse files
committed
Polish
1 parent 9f617be commit 2d4247b

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

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

+22-11
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,23 +31,24 @@
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
/**
3738
* {@link WebSocketClient} implementation for use with Reactor Netty.
3839
*
3940
* @author Rossen Stoyanchev
40-
* @author Usman Arshad
4141
* @since 5.0
4242
*/
4343
public class ReactorNettyWebSocketClient implements WebSocketClient {
4444

4545
private static final Log logger = LogFactory.getLog(ReactorNettyWebSocketClient.class);
4646

47-
private int maxFramePayloadLength = 65536;
47+
private int maxFramePayloadLength = NettyWebSocketSessionSupport.DEFAULT_FRAME_MAX_SIZE;
4848

4949
private final HttpClient httpClient;
5050

51+
5152
/**
5253
* Default constructor.
5354
*/
@@ -72,30 +73,40 @@ public HttpClient getHttpClient() {
7273
}
7374

7475
/**
75-
* Return the configured maxFramePayloadLength used by the configured {@link HttpClient}.
76-
* Default value of 65536 if not set.
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
7785
*/
78-
public int getMaxFramePayloadLength() {
79-
return maxFramePayloadLength;
86+
public void setMaxFramePayloadLength(int maxFramePayloadLength) {
87+
this.maxFramePayloadLength = maxFramePayloadLength;
8088
}
8189

8290
/**
83-
* Sets the maxFramePayloadLength to be used by the configured {@link HttpClient}.
91+
* Return the configured {@link #setMaxFramePayloadLength(int) maxFramePayloadLength}.
92+
* @since 5.2
8493
*/
85-
public void setMaxFramePayloadLength(int maxFramePayloadLength) {
86-
this.maxFramePayloadLength = maxFramePayloadLength;
94+
public int getMaxFramePayloadLength() {
95+
return maxFramePayloadLength;
8796
}
8897

98+
8999
@Override
90100
public Mono<Void> execute(URI url, WebSocketHandler handler) {
91101
return execute(url, new HttpHeaders(), handler);
92102
}
93103

94104
@Override
95105
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) {
106+
String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols());
96107
return getHttpClient()
97108
.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders))
98-
.websocket(StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols()), getMaxFramePayloadLength())
109+
.websocket(protocols, getMaxFramePayloadLength())
99110
.uri(url.toString())
100111
.handle((inbound, outbound) -> {
101112
HttpHeaders responseHeaders = toHttpHeaders(inbound);

0 commit comments

Comments
 (0)