Skip to content

Commit 630fc19

Browse files
committed
Add HttpRequest.getMethodValue
This commit introduces a new method in HttpRequest: `String getMethodValue`, which returns the HTTP method as a String. Furthermore, HttpRequest.getMethod() has been given a default implementation using this String value in combination with `HttpMethod.resolve`. Issue: SPR-15545
1 parent 31d1e26 commit 630fc19

26 files changed

+111
-42
lines changed

spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,6 +66,11 @@ public HttpMethod getMethod() {
6666
return this.httpMethod;
6767
}
6868

69+
@Override
70+
public String getMethodValue() {
71+
return this.httpMethod.name();
72+
}
73+
6974
public void setURI(URI uri) {
7075
this.uri = uri;
7176
}

spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public HttpMethod getMethod() {
8383
return this.httpMethod;
8484
}
8585

86+
@Override
87+
public String getMethodValue() {
88+
return this.httpMethod.name();
89+
}
90+
8691
@Override
8792
public String getContextPath() {
8893
return this.contextPath;

spring-web/src/main/java/org/springframework/http/HttpRequest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,15 @@ public interface HttpRequest extends HttpMessage {
3232
* @return the HTTP method as an HttpMethod enum value, or {@code null}
3333
* if not resolvable (e.g. in case of a non-standard HTTP method)
3434
*/
35-
HttpMethod getMethod();
35+
default HttpMethod getMethod() {
36+
return HttpMethod.resolve(getMethodValue());
37+
}
38+
39+
/**
40+
* Return the HTTP method of the request as a String
41+
* @return the HTTP method as a String
42+
*/
43+
String getMethodValue();
3644

3745
/**
3846
* Return the URI of the request.

spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,11 @@ public HttpMethod getMethod() {
4444
return this.request.getMethod();
4545
}
4646

47+
@Override
48+
public String getMethodValue() {
49+
return this.request.getMethodValue();
50+
}
51+
4752
@Override
4853
public URI getURI() {
4954
return this.request.getURI();

spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.http.protocol.HttpContext;
3131

3232
import org.springframework.http.HttpHeaders;
33-
import org.springframework.http.HttpMethod;
3433
import org.springframework.util.concurrent.FailureCallback;
3534
import org.springframework.util.concurrent.FutureAdapter;
3635
import org.springframework.util.concurrent.ListenableFuture;
@@ -69,8 +68,8 @@ final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncC
6968

7069

7170
@Override
72-
public HttpMethod getMethod() {
73-
return HttpMethod.resolve(this.httpRequest.getMethod());
71+
public String getMethodValue() {
72+
return this.httpRequest.getMethod();
7473
}
7574

7675
@Override

spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,8 +63,8 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR
6363

6464

6565
@Override
66-
public HttpMethod getMethod() {
67-
return HttpMethod.resolve(this.httpRequest.getMethod());
66+
public String getMethodValue() {
67+
return this.httpRequest.getMethod();
6868
}
6969

7070
@Override

spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
3131
import org.apache.http.protocol.HttpContext;
3232

3333
import org.springframework.http.HttpHeaders;
34-
import org.springframework.http.HttpMethod;
3534
import org.springframework.http.MediaType;
3635
import org.springframework.http.StreamingHttpOutputMessage;
3736

@@ -65,8 +64,8 @@ final class HttpComponentsStreamingClientHttpRequest extends AbstractClientHttpR
6564

6665

6766
@Override
68-
public HttpMethod getMethod() {
69-
return HttpMethod.resolve(this.httpRequest.getMethod());
67+
public String getMethodValue() {
68+
return this.httpRequest.getMethod();
7069
}
7170

7271
@Override

spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders heade
7575

7676
@Override
7777
public HttpMethod getMethod() {
78-
return httpMethod;
78+
return this.httpMethod;
79+
}
80+
81+
@Override
82+
public String getMethodValue() {
83+
return this.httpMethod.name();
7984
}
8085

8186
@Override

spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public HttpMethod getMethod() {
5959
return this.method;
6060
}
6161

62+
@Override
63+
public String getMethodValue() {
64+
return this.method.name();
65+
}
66+
6267
@Override
6368
public URI getURI() {
6469
return this.uri;

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public HttpMethod getMethod() {
7777
return this.method;
7878
}
7979

80+
@Override
81+
public String getMethodValue() {
82+
return this.method.name();
83+
}
84+
8085
@Override
8186
public URI getURI() {
8287
return this.uri;

0 commit comments

Comments
 (0)