|
|
|
@ -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. |
|
|
|
@ -22,6 +22,7 @@ import java.security.Principal; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
import java.util.function.Predicate; |
|
|
|
import java.util.function.Predicate; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@ -66,6 +67,9 @@ import org.springframework.web.server.ServerWebInputException; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class HandshakeWebSocketService implements WebSocketService, Lifecycle { |
|
|
|
public class HandshakeWebSocketService implements WebSocketService, Lifecycle { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For WebSocket upgrades in HTTP/2 (see RFC 8441)
|
|
|
|
|
|
|
|
private static final HttpMethod CONNECT_METHOD = HttpMethod.valueOf("CONNECT"); |
|
|
|
|
|
|
|
|
|
|
|
private static final String SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key"; |
|
|
|
private static final String SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol"; |
|
|
|
private static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol"; |
|
|
|
@ -201,9 +205,9 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { |
|
|
|
HttpMethod method = request.getMethod(); |
|
|
|
HttpMethod method = request.getMethod(); |
|
|
|
HttpHeaders headers = request.getHeaders(); |
|
|
|
HttpHeaders headers = request.getHeaders(); |
|
|
|
|
|
|
|
|
|
|
|
if (HttpMethod.GET != method) { |
|
|
|
if (HttpMethod.GET != method && CONNECT_METHOD != method) { |
|
|
|
return Mono.error(new MethodNotAllowedException( |
|
|
|
return Mono.error(new MethodNotAllowedException( |
|
|
|
request.getMethod(), Collections.singleton(HttpMethod.GET))); |
|
|
|
request.getMethod(), Set.of(HttpMethod.GET, CONNECT_METHOD))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) { |
|
|
|
if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) { |
|
|
|
|