|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
25 | 25 | import java.util.List;
|
26 | 26 | import java.util.Locale;
|
27 | 27 | import java.util.Map;
|
| 28 | +import java.util.Set; |
28 | 29 |
|
29 | 30 | import org.apache.commons.logging.Log;
|
30 | 31 | import org.apache.commons.logging.LogFactory;
|
|
77 | 78 | */
|
78 | 79 | public abstract class AbstractHandshakeHandler implements HandshakeHandler, Lifecycle {
|
79 | 80 |
|
| 81 | + // For WebSocket upgrades in HTTP/2 (see RFC 8441) |
| 82 | + private static final HttpMethod CONNECT_METHOD = HttpMethod.valueOf("CONNECT"); |
| 83 | + |
80 | 84 | private static final boolean tomcatWsPresent;
|
81 | 85 |
|
82 | 86 | private static final boolean jettyWsPresent;
|
@@ -210,11 +214,12 @@ public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse r
|
210 | 214 | logger.trace("Processing request " + request.getURI() + " with headers=" + headers);
|
211 | 215 | }
|
212 | 216 | try {
|
213 |
| - if (HttpMethod.GET != request.getMethod()) { |
| 217 | + HttpMethod httpMethod = request.getMethod(); |
| 218 | + if (HttpMethod.GET != httpMethod && CONNECT_METHOD != httpMethod) { |
214 | 219 | response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
|
215 |
| - response.getHeaders().setAllow(Collections.singleton(HttpMethod.GET)); |
| 220 | + response.getHeaders().setAllow(Set.of(HttpMethod.GET, CONNECT_METHOD)); |
216 | 221 | if (logger.isErrorEnabled()) {
|
217 |
| - logger.error("Handshake failed due to unexpected HTTP method: " + request.getMethod()); |
| 222 | + logger.error("Handshake failed due to unexpected HTTP method: " + httpMethod); |
218 | 223 | }
|
219 | 224 | return false;
|
220 | 225 | }
|
|
0 commit comments