Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CONNECT constant to HttpMethod #34195

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable {
*/
public static final HttpMethod DELETE = new HttpMethod("DELETE");

/**
* The HTTP method {@code CONNECT}.
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.6">RFC 9110, section 9.3.6</a>
*/
public static final HttpMethod CONNECT = new HttpMethod("CONNECT");

/**
* The HTTP method {@code OPTIONS}.
* @see <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2">HTTP 1.1, section 9.2</a>
Expand All @@ -83,7 +89,7 @@ public final class HttpMethod implements Comparable<HttpMethod>, 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;
Expand All @@ -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}.
*
* <p>Note that the returned value does not include any HTTP methods defined
* in WebDav.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ static List<Arguments> methodsWithConnectors() {
List<Arguments> result = new ArrayList<>();
for (Named<ClientHttpConnector> 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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethod
Set<HttpMethod> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Loading