Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,7 @@ public void setSecWebSocketProtocol(List<String> secWebSocketProtocols) {
* @return the value of the header
*/
public List<String> getSecWebSocketProtocol() {
List<String> values = get(SEC_WEBSOCKET_PROTOCOL);
if (CollectionUtils.isEmpty(values)) {
return Collections.emptyList();
}
else if (values.size() == 1) {
return getValuesAsList(SEC_WEBSOCKET_PROTOCOL);
}
else {
return values;
}
return getValuesAsList(SEC_WEBSOCKET_PROTOCOL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE;
import static org.springframework.web.socket.WebSocketHttpHeaders.SEC_WEBSOCKET_EXTENSIONS;
import static org.springframework.web.socket.WebSocketHttpHeaders.SEC_WEBSOCKET_PROTOCOL;

/**
* Tests for {@link WebSocketHttpHeaders}.
Expand Down Expand Up @@ -142,6 +143,14 @@ void parseWebSocketExtensions() {
assertThat(parsedExtensions).hasSize(3);
}

@Test // gh-37282
void getSecWebSocketProtocolWithMultipleHeaderValues() {
this.headers.add(SEC_WEBSOCKET_PROTOCOL, "foo");
this.headers.add(SEC_WEBSOCKET_PROTOCOL, "bar, baz");

assertThat(this.headers.getSecWebSocketProtocol()).containsExactly("foo", "bar", "baz");
}

@Test // gh-35792
void addAllViaWebSocketHttpHeadersApi() {
headers.add("green", "grape");
Expand Down