Browse Source

Polishing contribution

Closes gh-34362
pull/34400/head
rstoyanchev 10 months ago
parent
commit
ceffda7874
  1. 2
      spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java
  2. 21
      spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

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

@ -228,10 +228,19 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
handleInvalidUpgradeHeader(request, response); handleInvalidUpgradeHeader(request, response);
return false; return false;
} }
if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) { List<String> connectionValue = headers.getConnection();
if (!connectionValue.contains("Upgrade") && !connectionValue.contains("upgrade")) {
handleInvalidConnectHeader(request, response); handleInvalidConnectHeader(request, response);
return false; return false;
} }
String key = headers.getSecWebSocketKey();
if (key == null) {
if (logger.isErrorEnabled()) {
logger.error("Missing \"Sec-WebSocket-Key\" header");
}
response.setStatusCode(HttpStatus.BAD_REQUEST);
return false;
}
} }
if (!isWebSocketVersionSupported(headers)) { if (!isWebSocketVersionSupported(headers)) {
handleWebSocketVersionNotSupported(request, response); handleWebSocketVersionNotSupported(request, response);
@ -241,16 +250,6 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
response.setStatusCode(HttpStatus.FORBIDDEN); response.setStatusCode(HttpStatus.FORBIDDEN);
return false; return false;
} }
if (HttpMethod.GET == httpMethod) {
String wsKey = headers.getSecWebSocketKey();
if (wsKey == null) {
if (logger.isErrorEnabled()) {
logger.error("Missing \"Sec-WebSocket-Key\" header");
}
response.setStatusCode(HttpStatus.BAD_REQUEST);
return false;
}
}
} }
catch (IOException ex) { catch (IOException ex) {
throw new HandshakeFailureException( throw new HandshakeFailureException(

Loading…
Cancel
Save