Skip to content

Commit ceffda7

Browse files
committed
Polishing contribution
Closes gh-34362
1 parent 49f9b40 commit ceffda7

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 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.

spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,19 @@ public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse r
228228
handleInvalidUpgradeHeader(request, response);
229229
return false;
230230
}
231-
if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) {
231+
List<String> connectionValue = headers.getConnection();
232+
if (!connectionValue.contains("Upgrade") && !connectionValue.contains("upgrade")) {
232233
handleInvalidConnectHeader(request, response);
233234
return false;
234235
}
236+
String key = headers.getSecWebSocketKey();
237+
if (key == null) {
238+
if (logger.isErrorEnabled()) {
239+
logger.error("Missing \"Sec-WebSocket-Key\" header");
240+
}
241+
response.setStatusCode(HttpStatus.BAD_REQUEST);
242+
return false;
243+
}
235244
}
236245
if (!isWebSocketVersionSupported(headers)) {
237246
handleWebSocketVersionNotSupported(request, response);
@@ -241,16 +250,6 @@ public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse r
241250
response.setStatusCode(HttpStatus.FORBIDDEN);
242251
return false;
243252
}
244-
if (HttpMethod.GET == httpMethod) {
245-
String wsKey = headers.getSecWebSocketKey();
246-
if (wsKey == null) {
247-
if (logger.isErrorEnabled()) {
248-
logger.error("Missing \"Sec-WebSocket-Key\" header");
249-
}
250-
response.setStatusCode(HttpStatus.BAD_REQUEST);
251-
return false;
252-
}
253-
}
254253
}
255254
catch (IOException ex) {
256255
throw new HandshakeFailureException(

0 commit comments

Comments
 (0)