Skip to content

Commit

Permalink
Use HttpHeaders.ALLOW instead of String constant
Browse files Browse the repository at this point in the history
This commit changes "Allow" strings into HttpHeaders.ALLOW.

See gh-27356
  • Loading branch information
ydh6226 authored and poutsma committed Dec 2, 2021
1 parent e0979d0 commit a0ba808
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -68,7 +69,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
catch (HttpRequestMethodNotSupportedException ex) {
String[] supportedMethods = ex.getSupportedMethods();
if (supportedMethods != null) {
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
response.setHeader(HttpHeaders.ALLOW, StringUtils.arrayToDelimitedString(supportedMethods, ", "));
}
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -940,7 +941,7 @@ protected void doOptions(HttpServletRequest request, HttpServletResponse respons

if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
processRequest(request, response);
if (response.containsHeader("Allow")) {
if (response.containsHeader(HttpHeaders.ALLOW)) {
// Proper OPTIONS response coming from a handler - we're done.
return;
}
Expand All @@ -950,7 +951,7 @@ protected void doOptions(HttpServletRequest request, HttpServletResponse respons
super.doOptions(request, new HttpServletResponseWrapper(response) {
@Override
public void setHeader(String name, String value) {
if ("Allow".equals(name)) {
if (HttpHeaders.ALLOW.equals(name)) {
value = (StringUtils.hasLength(value) ? value + ", " : "") + HttpMethod.PATCH.name();
}
super.setHeader(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.ModelAndView;
Expand Down Expand Up @@ -155,7 +156,7 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons
throws Exception {

if (HttpMethod.OPTIONS.matches(request.getMethod())) {
response.setHeader("Allow", getAllowHeader());
response.setHeader(HttpHeaders.ALLOW, getAllowHeader());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
}

if (HttpMethod.OPTIONS.matches(request.getMethod())) {
response.setHeader("Allow", getAllowHeader());
response.setHeader(HttpHeaders.ALLOW, getAllowHeader());
return;
}

Expand Down

0 comments on commit a0ba808

Please sign in to comment.