From 2fb3eeba6f1dc9c76c548adb2b12132057c4b282 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 15 Sep 2017 14:11:20 +0200 Subject: [PATCH] Introduce ServerRequest.methodName() This commit introduces a methodName() method to the ServerRequest, returning the String name of the method. This method is useful for non-standard HTTP methods. --- .../reactive/function/server/MockServerRequest.java | 5 +++++ .../function/server/DefaultServerRequest.java | 6 ++---- .../reactive/function/server/RequestPredicates.java | 5 +++++ .../web/reactive/function/server/ServerRequest.java | 12 +++++++++++- .../server/support/ServerRequestWrapper.java | 5 +++++ .../reactive/function/server/MockServerRequest.java | 5 +++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java b/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java index d1269836ed..e21b795d53 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java @@ -109,6 +109,11 @@ public class MockServerRequest implements ServerRequest { return this.method; } + @Override + public String methodName() { + return this.method.name(); + } + @Override public URI uri() { return this.uri; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java index fdbf7270ea..18acc50106 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java @@ -35,7 +35,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpRange; import org.springframework.http.MediaType; import org.springframework.http.codec.HttpMessageReader; @@ -83,10 +82,9 @@ class DefaultServerRequest implements ServerRequest { } - @Override - public HttpMethod method() { - return request().getMethod(); + public String methodName() { + return request().getMethodValue(); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java index 108b1b6a34..b320eba6c7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java @@ -476,6 +476,11 @@ public abstract class RequestPredicates { return this.request.method(); } + @Override + public String methodName() { + return this.request.methodName(); + } + @Override public URI uri() { return this.request.uri(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java index ddf272ad61..c7f61c1fdb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java @@ -59,9 +59,19 @@ public interface ServerRequest { /** * Return the HTTP method. + * @return the HTTP method as an HttpMethod enum value, or {@code null} + * if not resolvable (e.g. in case of a non-standard HTTP method) */ @Nullable - HttpMethod method(); + default HttpMethod method() { + return HttpMethod.resolve(methodName()); + } + + /** + * Return the name of the HTTP method. + * @return the HTTP method as a String + */ + String methodName(); /** * Return the request URI. diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java index faf65c6f5c..07c59e052c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java @@ -79,6 +79,11 @@ public class ServerRequestWrapper implements ServerRequest { return this.delegate.method(); } + @Override + public String methodName() { + return this.delegate.methodName(); + } + @Override public URI uri() { return this.delegate.uri(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java index 81aec8096b..b536b392e2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java @@ -108,6 +108,11 @@ public class MockServerRequest implements ServerRequest { return this.method; } + @Override + public String methodName() { + return this.method.name(); + } + @Override public URI uri() { return this.uri;