diff --git a/spring-web/src/main/java/org/springframework/http/HttpMethod.java b/spring-web/src/main/java/org/springframework/http/HttpMethod.java index 95debcfbcaa2..5a1185073678 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -71,6 +71,12 @@ public final class HttpMethod implements Comparable, Serializable { */ public static final HttpMethod DELETE = new HttpMethod("DELETE"); + /** + * The HTTP method {@code CONNECT}. + * @see RFC 9110, section 9.3.6 + */ + public static final HttpMethod CONNECT = new HttpMethod("CONNECT"); + /** * The HTTP method {@code OPTIONS}. * @see HTTP 1.1, section 9.2 @@ -83,7 +89,7 @@ public final class HttpMethod implements Comparable, Serializable { */ public static final HttpMethod TRACE = new HttpMethod("TRACE"); - private static final HttpMethod[] values = new HttpMethod[] { GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE }; + private static final HttpMethod[] values = new HttpMethod[] { GET, HEAD, POST, PUT, PATCH, DELETE, CONNECT, OPTIONS, TRACE }; private final String name; @@ -97,7 +103,7 @@ private HttpMethod(String name) { * Returns an array containing the standard HTTP methods. Specifically, * this method returns an array containing {@link #GET}, {@link #HEAD}, * {@link #POST}, {@link #PUT}, {@link #PATCH}, {@link #DELETE}, - * {@link #OPTIONS}, and {@link #TRACE}. + * {@link #CONNECT}, {@link #OPTIONS}, and {@link #TRACE}. * *

Note that the returned value does not include any HTTP methods defined * in WebDav. @@ -122,6 +128,7 @@ public static HttpMethod valueOf(String method) { case "PUT" -> PUT; case "PATCH" -> PATCH; case "DELETE" -> DELETE; + case "CONNECT" -> CONNECT; case "OPTIONS" -> OPTIONS; case "TRACE" -> TRACE; default -> new HttpMethod(method); diff --git a/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java b/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java index 055149ea53e1..47154980844f 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpMethodTests.java @@ -44,12 +44,12 @@ void comparison() { void values() { HttpMethod[] values = HttpMethod.values(); assertThat(values).containsExactly(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.POST, HttpMethod.PUT, - HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.OPTIONS, HttpMethod.TRACE); + HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.CONNECT, HttpMethod.OPTIONS, HttpMethod.TRACE); // check defensive copy values[0] = HttpMethod.POST; assertThat(HttpMethod.values()).containsExactly(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.POST, HttpMethod.PUT, - HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.OPTIONS, HttpMethod.TRACE); + HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.CONNECT, HttpMethod.OPTIONS, HttpMethod.TRACE); } @Test diff --git a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java index dcd98a835ff1..dd6874a203c3 100644 --- a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java @@ -271,6 +271,9 @@ static List methodsWithConnectors() { List result = new ArrayList<>(); for (Named connector : connectors()) { for (HttpMethod method : HttpMethod.values()) { + if (HttpMethod.CONNECT.equals(method) && List.of("HttpComponents", "Jdk").contains(connector.getName())) { + continue; + } result.add(Arguments.of(connector, method)); } } diff --git a/spring-web/src/test/java/org/springframework/web/bind/annotation/RequestMethodTests.java b/spring-web/src/test/java/org/springframework/web/bind/annotation/RequestMethodTests.java index 7c628c91922e..553c033e596c 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/annotation/RequestMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/annotation/RequestMethodTests.java @@ -41,6 +41,10 @@ void resolveString() { @Test void resolveHttpMethod() { for (HttpMethod httpMethod : HttpMethod.values()) { + if (HttpMethod.CONNECT.equals(httpMethod)) { + assertThat(RequestMethod.resolve(httpMethod)).isNull(); + continue; + } RequestMethod requestMethod = RequestMethod.resolve(httpMethod); assertThat(requestMethod).isNotNull(); assertThat(requestMethod.name()).isEqualTo(httpMethod.name()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index 5923e9ead263..3589ffb9ab61 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -517,7 +517,7 @@ private static Set initAllowedHttpMethods(Set declaredMethod Set result = CollectionUtils.newLinkedHashSet(declaredMethods.size()); if (declaredMethods.isEmpty()) { for (HttpMethod method : HttpMethod.values()) { - if (method != HttpMethod.TRACE) { + if (method != HttpMethod.TRACE && method != HttpMethod.CONNECT) { result.add(method); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java index 4f5a3f7907e2..70484898241a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java @@ -146,7 +146,7 @@ private void initAllowHeader() { if (this.supportedMethods == null) { allowedMethods = new ArrayList<>(HttpMethod.values().length - 1); for (HttpMethod method : HttpMethod.values()) { - if (method != HttpMethod.TRACE) { + if (method != HttpMethod.TRACE && method != HttpMethod.CONNECT) { allowedMethods.add(method.name()); } }