From 5489d56d594b41a681161f757c5832959b6d1e67 Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Sat, 4 Jan 2025 23:01:50 +0100 Subject: [PATCH 1/7] Update @see links for HttpMethods to reference RFC 9110 Replaced outdated references to HTTP 1.1 section links (RFC 2616) with updated references to RFC 9110. The original document has been superseded. --- .../java/org/springframework/http/HttpMethod.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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..af91c1d1647f 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -37,25 +37,25 @@ public final class HttpMethod implements Comparable, Serializable { /** * The HTTP method {@code GET}. - * @see HTTP 1.1, section 9.3 + * @see RFC 9110, section 9.3.1 */ public static final HttpMethod GET = new HttpMethod("GET"); /** * The HTTP method {@code HEAD}. - * @see HTTP 1.1, section 9.4 + * @see RFC 9110, section 9.3.2 */ public static final HttpMethod HEAD = new HttpMethod("HEAD"); /** * The HTTP method {@code POST}. - * @see HTTP 1.1, section 9.5 + * @see RFC 9110, section 9.3.3 */ public static final HttpMethod POST = new HttpMethod("POST"); /** * The HTTP method {@code PUT}. - * @see HTTP 1.1, section 9.6 + * @see RFC 9110, section 9.3.4 */ public static final HttpMethod PUT = new HttpMethod("PUT"); @@ -67,19 +67,19 @@ public final class HttpMethod implements Comparable, Serializable { /** * The HTTP method {@code DELETE}. - * @see HTTP 1.1, section 9.7 + * @see RFC 9110, section 9.3.5 */ public static final HttpMethod DELETE = new HttpMethod("DELETE"); /** * The HTTP method {@code OPTIONS}. - * @see HTTP 1.1, section 9.2 + * @see RFC 9110, section 9.3.7 */ public static final HttpMethod OPTIONS = new HttpMethod("OPTIONS"); /** * The HTTP method {@code TRACE}. - * @see HTTP 1.1, section 9.8 + * @see RFC 9110, section 9.3.8 */ public static final HttpMethod TRACE = new HttpMethod("TRACE"); From a3c820c06d6e0b7653f330a531cdf71f5f8d6ddc Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Sat, 4 Jan 2025 23:08:59 +0100 Subject: [PATCH 2/7] Add support for HTTP method CONNECT in HttpMethod Introduced a new constant CONNECT with reference to RFC 9110. Updated values array and valueOf method. --- .../java/org/springframework/http/HttpMethod.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 af91c1d1647f..55ad75ec3fb6 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 RFC 9110, section 9.3.7 @@ -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); From fce389e2a76a8aeeabcf0d4375dec0cf148c992a Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Sat, 4 Jan 2025 23:18:26 +0100 Subject: [PATCH 3/7] Update HttpMethodTests to include HTTP method CONNECT Modified the values test in HttpMethodTests to include the CONNECT method. --- .../test/java/org/springframework/http/HttpMethodTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From be8483df5b0d0ed7061e07fabdfe00e0368da5f2 Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Sat, 4 Jan 2025 23:57:10 +0100 Subject: [PATCH 4/7] Skip CONNECT for unsupported connectors in tests The CONNECT method is not supported by HttpComponentsClientHttpConnector and JdkClientHttpConnector. --- .../http/client/reactive/ClientHttpConnectorTests.java | 3 +++ 1 file changed, 3 insertions(+) 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)); } } From 18106b3cbd6145da82e1a03cbbd419d6baa92256 Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Sun, 5 Jan 2025 00:19:25 +0100 Subject: [PATCH 5/7] Update RequestMethodTests test to handle CONNECT The CONNECT http method is primarily used for establishing tunnels and is not relevant for RequestMethod. --- .../web/bind/annotation/RequestMethodTests.java | 4 ++++ 1 file changed, 4 insertions(+) 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()); From b224feacced410cf7074b9198d4bd0a702dc3e15 Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Sun, 5 Jan 2025 01:01:51 +0100 Subject: [PATCH 6/7] Exclude CONNECT from allowed HTTP methods Updated initAllowedHttpMethods in WebContentGenerator and RequestMappingInfoHandlerMapping to explicitly exclude the CONNECT method. --- .../servlet/mvc/method/RequestMappingInfoHandlerMapping.java | 2 +- .../web/servlet/support/WebContentGenerator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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()); } } From 9a1a18129bd2854f5d7bbb21b4459ab8e262f646 Mon Sep 17 00:00:00 2001 From: Vladimir Perfilev Date: Mon, 6 Jan 2025 10:28:29 +0100 Subject: [PATCH 7/7] Revert "Update @see links for HttpMethods" This reverts commit 5489d56 as it is unrelated to the addition of CONNECT to HttpMethod. --- .../java/org/springframework/http/HttpMethod.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 55ad75ec3fb6..5a1185073678 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -37,25 +37,25 @@ public final class HttpMethod implements Comparable, Serializable { /** * The HTTP method {@code GET}. - * @see RFC 9110, section 9.3.1 + * @see HTTP 1.1, section 9.3 */ public static final HttpMethod GET = new HttpMethod("GET"); /** * The HTTP method {@code HEAD}. - * @see RFC 9110, section 9.3.2 + * @see HTTP 1.1, section 9.4 */ public static final HttpMethod HEAD = new HttpMethod("HEAD"); /** * The HTTP method {@code POST}. - * @see RFC 9110, section 9.3.3 + * @see HTTP 1.1, section 9.5 */ public static final HttpMethod POST = new HttpMethod("POST"); /** * The HTTP method {@code PUT}. - * @see RFC 9110, section 9.3.4 + * @see HTTP 1.1, section 9.6 */ public static final HttpMethod PUT = new HttpMethod("PUT"); @@ -67,7 +67,7 @@ public final class HttpMethod implements Comparable, Serializable { /** * The HTTP method {@code DELETE}. - * @see RFC 9110, section 9.3.5 + * @see HTTP 1.1, section 9.7 */ public static final HttpMethod DELETE = new HttpMethod("DELETE"); @@ -79,13 +79,13 @@ public final class HttpMethod implements Comparable, Serializable { /** * The HTTP method {@code OPTIONS}. - * @see RFC 9110, section 9.3.7 + * @see HTTP 1.1, section 9.2 */ public static final HttpMethod OPTIONS = new HttpMethod("OPTIONS"); /** * The HTTP method {@code TRACE}. - * @see RFC 9110, section 9.3.8 + * @see HTTP 1.1, section 9.8 */ public static final HttpMethod TRACE = new HttpMethod("TRACE");