Merge branch '6.2.x'
This commit is contained in:
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -149,7 +149,7 @@ public class WebSocketHttpHeaders extends HttpHeaders {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the {@code Sec-WebSocket-Key} header.
|
||||
* Returns the value of the {@code Sec-WebSocket-Protocol} header.
|
||||
* @return the value of the header
|
||||
*/
|
||||
public List<String> getSecWebSocketProtocol() {
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
|
||||
}
|
||||
try {
|
||||
HttpMethod httpMethod = request.getMethod();
|
||||
if (HttpMethod.GET != httpMethod && CONNECT_METHOD != httpMethod) {
|
||||
if (HttpMethod.GET != httpMethod && !CONNECT_METHOD.equals(httpMethod)) {
|
||||
response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
|
||||
response.getHeaders().setAllow(Set.of(HttpMethod.GET, CONNECT_METHOD));
|
||||
if (logger.isErrorEnabled()) {
|
||||
@@ -183,13 +183,24 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) {
|
||||
handleInvalidUpgradeHeader(request, response);
|
||||
return false;
|
||||
}
|
||||
if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) {
|
||||
handleInvalidConnectHeader(request, response);
|
||||
return false;
|
||||
if (HttpMethod.GET == httpMethod) {
|
||||
if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) {
|
||||
handleInvalidUpgradeHeader(request, response);
|
||||
return false;
|
||||
}
|
||||
List<String> connectionValue = headers.getConnection();
|
||||
if (!connectionValue.contains("Upgrade") && !connectionValue.contains("upgrade")) {
|
||||
handleInvalidConnectHeader(request, response);
|
||||
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)) {
|
||||
handleWebSocketVersionNotSupported(request, response);
|
||||
@@ -199,14 +210,6 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
|
||||
response.setStatusCode(HttpStatus.FORBIDDEN);
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
throw new HandshakeFailureException(
|
||||
|
||||
Reference in New Issue
Block a user