Add HttpMethod.values() returning an un-modifiable list of HTTP methods known by the declaring interface

This commit is contained in:
Julien Viet
2020-01-20 10:40:07 +01:00
parent 46eaf41f8b
commit a5b2fa5434
2 changed files with 47 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ package io.vertx.core.http;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.http.impl.HttpMethodImpl;
import java.util.List;
import java.util.Objects;
/**
@@ -180,6 +181,8 @@ public interface HttpMethod {
*/
HttpMethod SEARCH = new HttpMethodImpl(io.netty.handler.codec.http.HttpMethod.valueOf("SEARCH"));
/**
* @return the method name
*/
@@ -272,4 +275,11 @@ public interface HttpMethod {
return new HttpMethodImpl(io.netty.handler.codec.http.HttpMethod.valueOf(value));
}
}
/**
* @return an un-modifiable list of known HTTP methods
*/
static List<HttpMethod> values() {
return HttpMethodImpl.ALL;
}
}

View File

@@ -12,10 +12,47 @@ package io.vertx.core.http.impl;
import io.vertx.core.http.HttpMethod;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class HttpMethodImpl implements HttpMethod {
public static final List<HttpMethod> ALL = Collections.unmodifiableList(Arrays.asList(
HttpMethod.OPTIONS,
HttpMethod.GET,
HttpMethod.HEAD,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.DELETE,
HttpMethod.TRACE,
HttpMethod.CONNECT,
HttpMethod.PATCH,
HttpMethod.PROPFIND,
HttpMethod.PROPPATCH,
HttpMethod.MKCOL,
HttpMethod.COPY,
HttpMethod.MOVE,
HttpMethod.LOCK,
HttpMethod.UNLOCK,
HttpMethod.MKCALENDAR,
HttpMethod.VERSION_CONTROL,
HttpMethod.REPORT,
HttpMethod.CHECKIN,
HttpMethod.CHECKOUT,
HttpMethod.UNCHECKOUT,
HttpMethod.MKWORKSPACE,
HttpMethod.UPDATE,
HttpMethod.LABEL,
HttpMethod.MERGE,
HttpMethod.BASELINE_CONTROL,
HttpMethod.MKACTIVITY,
HttpMethod.ORDERPATCH,
HttpMethod.ACL,
HttpMethod.SEARCH
));
public static io.netty.handler.codec.http.HttpMethod toNetty(HttpMethod method) {
if (method instanceof HttpMethodImpl) {
return ((HttpMethodImpl) method).nettyMethod;