Use HttpHeaders.ALLOW instead of String constant
This commit changes "Allow" strings into HttpHeaders.ALLOW. See gh-27356
This commit is contained in:
parent
e0979d0e74
commit
a0ba808217
|
@ -24,6 +24,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
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;
|
||||
|
@ -68,7 +69,7 @@ public class HttpRequestHandlerServlet extends HttpServlet {
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.springframework.context.i18n.SimpleLocaleContext;
|
|||
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;
|
||||
|
@ -940,7 +941,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -950,7 +951,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||
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);
|
||||
|
|
|
@ -20,6 +20,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
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;
|
||||
|
@ -155,7 +156,7 @@ public abstract class AbstractController extends WebContentGenerator implements
|
|||
throws Exception {
|
||||
|
||||
if (HttpMethod.OPTIONS.matches(request.getMethod())) {
|
||||
response.setHeader("Allow", getAllowHeader());
|
||||
response.setHeader(HttpHeaders.ALLOW, getAllowHeader());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -560,7 +560,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
|||
}
|
||||
|
||||
if (HttpMethod.OPTIONS.matches(request.getMethod())) {
|
||||
response.setHeader("Allow", getAllowHeader());
|
||||
response.setHeader(HttpHeaders.ALLOW, getAllowHeader());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue