Skip to content

Commit 913eca9

Browse files
committed
ReactorNettyRequestUpgradeStrategy uses unique builder per request
See gh-25315
1 parent 6c7f18e commit 913eca9

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class ReactorNettyRequestUpgradeStrategy implements RequestUpgradeStrateg
5757
* @since 5.2.6
5858
*/
5959
public ReactorNettyRequestUpgradeStrategy() {
60-
this(WebsocketServerSpec.builder());
60+
this(WebsocketServerSpec::builder);
6161
}
6262

6363

@@ -83,7 +83,7 @@ public WebsocketServerSpec getWebsocketServerSpec() {
8383
return buildSpec(null);
8484
}
8585

86-
private WebsocketServerSpec buildSpec(@Nullable String subProtocol) {
86+
WebsocketServerSpec buildSpec(@Nullable String subProtocol) {
8787
WebsocketServerSpec.Builder builder = this.specBuilderSupplier.get();
8888
if (subProtocol != null) {
8989
builder.protocols(subProtocol);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.web.reactive.socket.server.upgrade;
17+
18+
import org.junit.jupiter.api.Test;
19+
import reactor.netty.http.server.WebsocketServerSpec;
20+
21+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
22+
23+
/**
24+
* Unit tests for {@link ReactorNettyRequestUpgradeStrategy}.
25+
* @author Rossen Stoyanchev
26+
*/
27+
public class ReactorNettyRequestUpgradeStrategyTests {
28+
29+
@Test // gh-25315
30+
void defaultWebSocketSpecBuilderIsUniquePerRequest() {
31+
ReactorNettyRequestUpgradeStrategy strategy = new ReactorNettyRequestUpgradeStrategy();
32+
WebsocketServerSpec spec1 = strategy.buildSpec("p1");
33+
WebsocketServerSpec spec2 = strategy.getWebsocketServerSpec();
34+
35+
assertThat(spec1.protocols()).isEqualTo("p1");
36+
assertThat(spec2.protocols()).isNull();
37+
}
38+
39+
}

0 commit comments

Comments
 (0)