1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
31
31
import org .springframework .web .reactive .socket .HandshakeInfo ;
32
32
import org .springframework .web .reactive .socket .WebSocketHandler ;
33
33
import org .springframework .web .reactive .socket .WebSocketSession ;
34
+ import org .springframework .web .reactive .socket .adapter .NettyWebSocketSessionSupport ;
34
35
import org .springframework .web .reactive .socket .adapter .ReactorNettyWebSocketSession ;
35
36
36
37
/**
37
38
* {@link WebSocketClient} implementation for use with Reactor Netty.
38
39
*
39
40
* @author Rossen Stoyanchev
40
- * @author Usman Arshad
41
41
* @since 5.0
42
42
*/
43
43
public class ReactorNettyWebSocketClient implements WebSocketClient {
44
44
45
45
private static final Log logger = LogFactory .getLog (ReactorNettyWebSocketClient .class );
46
46
47
- private int maxFramePayloadLength = 65536 ;
47
+ private int maxFramePayloadLength = NettyWebSocketSessionSupport . DEFAULT_FRAME_MAX_SIZE ;
48
48
49
49
private final HttpClient httpClient ;
50
50
51
+
51
52
/**
52
53
* Default constructor.
53
54
*/
@@ -72,30 +73,40 @@ public HttpClient getHttpClient() {
72
73
}
73
74
74
75
/**
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
77
85
*/
78
- public int getMaxFramePayloadLength ( ) {
79
- return maxFramePayloadLength ;
86
+ public void setMaxFramePayloadLength ( int maxFramePayloadLength ) {
87
+ this . maxFramePayloadLength = maxFramePayloadLength ;
80
88
}
81
89
82
90
/**
83
- * Sets the maxFramePayloadLength to be used by the configured {@link HttpClient}.
91
+ * Return the configured {@link #setMaxFramePayloadLength(int) maxFramePayloadLength}.
92
+ * @since 5.2
84
93
*/
85
- public void setMaxFramePayloadLength ( int maxFramePayloadLength ) {
86
- this . maxFramePayloadLength = maxFramePayloadLength ;
94
+ public int getMaxFramePayloadLength ( ) {
95
+ return maxFramePayloadLength ;
87
96
}
88
97
98
+
89
99
@ Override
90
100
public Mono <Void > execute (URI url , WebSocketHandler handler ) {
91
101
return execute (url , new HttpHeaders (), handler );
92
102
}
93
103
94
104
@ Override
95
105
public Mono <Void > execute (URI url , HttpHeaders requestHeaders , WebSocketHandler handler ) {
106
+ String protocols = StringUtils .collectionToCommaDelimitedString (handler .getSubProtocols ());
96
107
return getHttpClient ()
97
108
.headers (nettyHeaders -> setNettyHeaders (requestHeaders , nettyHeaders ))
98
- .websocket (StringUtils . collectionToCommaDelimitedString ( handler . getSubProtocols ()) , getMaxFramePayloadLength ())
109
+ .websocket (protocols , getMaxFramePayloadLength ())
99
110
.uri (url .toString ())
100
111
.handle ((inbound , outbound ) -> {
101
112
HttpHeaders responseHeaders = toHttpHeaders (inbound );
0 commit comments