Browse Source

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.
pull/1529/head
Arjen Poutsma 7 years ago
parent
commit
2fb3eeba6f
  1. 5
      spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java
  2. 6
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java
  3. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java
  4. 12
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java
  5. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java
  6. 5
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java

5
spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java

@ -109,6 +109,11 @@ public class MockServerRequest implements ServerRequest { @@ -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;

6
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java

@ -35,7 +35,6 @@ import reactor.core.publisher.Mono; @@ -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 { @@ -83,10 +82,9 @@ class DefaultServerRequest implements ServerRequest {
}
@Override
public HttpMethod method() {
return request().getMethod();
public String methodName() {
return request().getMethodValue();
}
@Override

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java

@ -476,6 +476,11 @@ public abstract class RequestPredicates { @@ -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();

12
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java

@ -59,9 +59,19 @@ public interface ServerRequest { @@ -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.

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java

@ -79,6 +79,11 @@ public class ServerRequestWrapper implements ServerRequest { @@ -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();

5
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java

@ -108,6 +108,11 @@ public class MockServerRequest implements ServerRequest { @@ -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;

Loading…
Cancel
Save