Consistent HttpMethod identity comparisons

This commit is contained in:
Juergen Hoeller
2018-02-18 22:01:22 +01:00
parent d1e9161ca6
commit 0de36d2883
17 changed files with 69 additions and 100 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.
@@ -848,7 +848,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-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.
@@ -434,16 +434,16 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
Set<HttpMethod> result = new LinkedHashSet<>(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-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.
@@ -174,7 +174,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
if (this.supportedMethods == null) {
allowedMethods = new ArrayList<>(HttpMethod.values().length - 1);
for (HttpMethod method : HttpMethod.values()) {
if (!HttpMethod.TRACE.equals(method)) {
if (method != HttpMethod.TRACE) {
allowedMethods.add(method.name());
}
}
@@ -191,13 +191,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
*/
@Nullable
protected String getAllowHeader() {