Consistent HttpMethod identity comparisons

(cherry picked from commit 0de36d2)
This commit is contained in:
Juergen Hoeller
2018-02-18 22:01:22 +01:00
parent 87abdb92da
commit caed04473e
10 changed files with 47 additions and 66 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -839,7 +839,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
throws ServletException, IOException {
HttpMethod httpMethod = HttpMethod.resolve(request.getMethod());
if (HttpMethod.PATCH == httpMethod || httpMethod == null) {
if (httpMethod == HttpMethod.PATCH || httpMethod == null) {
processRequest(request, response);
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -439,16 +439,16 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
Set<HttpMethod> result = new LinkedHashSet<HttpMethod>(declaredMethods.size());
if (declaredMethods.isEmpty()) {
for (HttpMethod method : HttpMethod.values()) {
if (!HttpMethod.TRACE.equals(method)) {
if (method != HttpMethod.TRACE) {
result.add(method);
}
}
}
else {
boolean hasHead = declaredMethods.contains("HEAD");
for (String method : declaredMethods) {
result.add(HttpMethod.valueOf(method));
if (!hasHead && "GET".equals(method)) {
HttpMethod httpMethod = HttpMethod.valueOf(method);
result.add(httpMethod);
if (httpMethod == HttpMethod.GET) {
result.add(HttpMethod.HEAD);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -173,7 +173,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
if (this.supportedMethods == null) {
allowedMethods = new ArrayList<String>(HttpMethod.values().length - 1);
for (HttpMethod method : HttpMethod.values()) {
if (!HttpMethod.TRACE.equals(method)) {
if (method != HttpMethod.TRACE) {
allowedMethods.add(method.name());
}
}
@@ -190,13 +190,13 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
}
/**
* Return the "Allow" header value to use in response to an HTTP OPTIONS
* request based on the configured {@link #setSupportedMethods supported
* methods} also automatically adding "OPTIONS" to the list even if not
* present as a supported method. This means sub-classes don't have to
* explicitly list "OPTIONS" as a supported method as long as HTTP OPTIONS
* requests are handled before making a call to
* {@link #checkRequest(HttpServletRequest)}.
* Return the "Allow" header value to use in response to an HTTP OPTIONS request
* based on the configured {@link #setSupportedMethods supported methods} also
* automatically adding "OPTIONS" to the list even if not present as a supported
* method. This means subclasses don't have to explicitly list "OPTIONS" as a
* supported method as long as HTTP OPTIONS requests are handled before making a
* call to {@link #checkRequest(HttpServletRequest)}.
* @since 4.3
*/
protected String getAllowHeader() {
return this.allowHeader;