Skip to content

Commit 72318e6

Browse files
committed
Refactor: Use HttpMethod and HttpHeaders instead of literal string.
Signed-off-by: Mengqi Xu <[email protected]>
1 parent c970a60 commit 72318e6

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.springframework.core.log.LogFormatUtils;
5151
import org.springframework.core.task.AsyncTaskExecutor;
5252
import org.springframework.core.task.SimpleAsyncTaskExecutor;
53+
import org.springframework.http.HttpHeaders;
5354
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
5455
import org.springframework.http.converter.HttpMessageConverter;
5556
import org.springframework.http.converter.StringHttpMessageConverter;
@@ -871,7 +872,7 @@ protected boolean supportsInternal(HandlerMethod handlerMethod) {
871872
mav = invokeHandlerMethod(request, response, handlerMethod);
872873
}
873874

874-
if (!response.containsHeader(HEADER_CACHE_CONTROL)) {
875+
if (!response.containsHeader(HttpHeaders.CACHE_CONTROL)) {
875876
if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
876877
applyCacheSeconds(response, this.cacheSecondsForSessionAttributeHandlers);
877878
}

spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@
6060
*/
6161
public abstract class WebContentGenerator extends WebApplicationObjectSupport {
6262

63-
/** HTTP method "GET". */
64-
public static final String METHOD_GET = "GET";
65-
66-
/** HTTP method "HEAD". */
67-
public static final String METHOD_HEAD = "HEAD";
68-
69-
/** HTTP method "POST". */
70-
public static final String METHOD_POST = "POST";
71-
72-
protected static final String HEADER_CACHE_CONTROL = "Cache-Control";
73-
74-
7563
/** Set of supported HTTP methods. */
7664
private @Nullable Set<String> supportedMethods;
7765

@@ -103,9 +91,9 @@ public WebContentGenerator() {
10391
public WebContentGenerator(boolean restrictDefaultSupportedMethods) {
10492
if (restrictDefaultSupportedMethods) {
10593
this.supportedMethods = CollectionUtils.newLinkedHashSet(3);
106-
this.supportedMethods.add(METHOD_GET);
107-
this.supportedMethods.add(METHOD_HEAD);
108-
this.supportedMethods.add(METHOD_POST);
94+
this.supportedMethods.add(HttpMethod.GET.name());
95+
this.supportedMethods.add(HttpMethod.HEAD.name());
96+
this.supportedMethods.add(HttpMethod.POST.name());
10997
}
11098
initAllowHeader();
11199
}
@@ -292,7 +280,7 @@ protected final void prepareResponse(HttpServletResponse response) {
292280
}
293281
if (this.varyByRequestHeaders != null) {
294282
for (String value : getVaryRequestHeadersToAdd(response, this.varyByRequestHeaders)) {
295-
response.addHeader("Vary", value);
283+
response.addHeader(HttpHeaders.VARY, value);
296284
}
297285
}
298286
}
@@ -307,7 +295,7 @@ protected final void applyCacheControl(HttpServletResponse response, CacheContro
307295
String ccValue = cacheControl.getHeaderValue();
308296
if (ccValue != null) {
309297
// Set computed HTTP 1.1 Cache-Control header
310-
response.setHeader(HEADER_CACHE_CONTROL, ccValue);
298+
response.setHeader(HttpHeaders.CACHE_CONTROL, ccValue);
311299
}
312300
}
313301

0 commit comments

Comments
 (0)