Skip to content

Commit

Permalink
Refactor: Use HttpMethod and HttpHeaders instead of literal string.
Browse files Browse the repository at this point in the history
Signed-off-by: Mengqi Xu <2663479778@qq.com>
  • Loading branch information
remeio committed Jan 9, 2025
1 parent c970a60 commit 72318e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.springframework.core.log.LogFormatUtils;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
Expand Down Expand Up @@ -871,7 +872,7 @@ protected boolean supportsInternal(HandlerMethod handlerMethod) {
mav = invokeHandlerMethod(request, response, handlerMethod);
}

if (!response.containsHeader(HEADER_CACHE_CONTROL)) {
if (!response.containsHeader(HttpHeaders.CACHE_CONTROL)) {
if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
applyCacheSeconds(response, this.cacheSecondsForSessionAttributeHandlers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@
*/
public abstract class WebContentGenerator extends WebApplicationObjectSupport {

/** HTTP method "GET". */
public static final String METHOD_GET = "GET";

/** HTTP method "HEAD". */
public static final String METHOD_HEAD = "HEAD";

/** HTTP method "POST". */
public static final String METHOD_POST = "POST";

protected static final String HEADER_CACHE_CONTROL = "Cache-Control";


/** Set of supported HTTP methods. */
private @Nullable Set<String> supportedMethods;

Expand Down Expand Up @@ -103,9 +91,9 @@ public WebContentGenerator() {
public WebContentGenerator(boolean restrictDefaultSupportedMethods) {
if (restrictDefaultSupportedMethods) {
this.supportedMethods = CollectionUtils.newLinkedHashSet(3);
this.supportedMethods.add(METHOD_GET);
this.supportedMethods.add(METHOD_HEAD);
this.supportedMethods.add(METHOD_POST);
this.supportedMethods.add(HttpMethod.GET.name());
this.supportedMethods.add(HttpMethod.HEAD.name());
this.supportedMethods.add(HttpMethod.POST.name());
}
initAllowHeader();
}
Expand Down Expand Up @@ -292,7 +280,7 @@ protected final void prepareResponse(HttpServletResponse response) {
}
if (this.varyByRequestHeaders != null) {
for (String value : getVaryRequestHeadersToAdd(response, this.varyByRequestHeaders)) {
response.addHeader("Vary", value);
response.addHeader(HttpHeaders.VARY, value);
}
}
}
Expand All @@ -307,7 +295,7 @@ protected final void applyCacheControl(HttpServletResponse response, CacheContro
String ccValue = cacheControl.getHeaderValue();
if (ccValue != null) {
// Set computed HTTP 1.1 Cache-Control header
response.setHeader(HEADER_CACHE_CONTROL, ccValue);
response.setHeader(HttpHeaders.CACHE_CONTROL, ccValue);
}
}

Expand Down

0 comments on commit 72318e6

Please sign in to comment.