Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Use HttpMethod and HttpHeaders instead of literal string. #34222

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ protected HandlerExecutionChain getCorsHandlerExecutionChain(
private static class SimpleHandler extends WebContentGenerator implements HttpRequestHandler {

SimpleHandler() {
super(METHOD_GET);
super(HttpMethod.GET.name());
}

@Override
Expand Down
Loading