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

@@ -23,7 +23,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Random;
@@ -515,7 +514,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
protected void sendMethodNotAllowed(ServerHttpResponse response, HttpMethod... httpMethods) {
logger.warn("Sending Method Not Allowed (405)");
response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
response.getHeaders().setAllow(new HashSet<HttpMethod>(Arrays.asList(httpMethods)));
response.getHeaders().setAllow(new LinkedHashSet<HttpMethod>(Arrays.asList(httpMethods)));
}
@@ -545,7 +544,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
if (HttpMethod.GET == request.getMethod()) {
if (request.getMethod() == HttpMethod.GET) {
addNoCacheHeaders(response);
if (checkOrigin(request, response)) {
response.getHeaders().setContentType(new MediaType("application", "json", UTF8_CHARSET));
@@ -555,14 +554,14 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
}
else if (HttpMethod.OPTIONS == request.getMethod()) {
else if (request.getMethod() == HttpMethod.OPTIONS) {
if (checkOrigin(request, response)) {
addCacheHeaders(response);
response.setStatusCode(HttpStatus.NO_CONTENT);
}
}
else {
sendMethodNotAllowed(response, HttpMethod.OPTIONS, HttpMethod.GET);
sendMethodNotAllowed(response, HttpMethod.GET, HttpMethod.OPTIONS);
}
}
};
@@ -590,7 +589,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
if (!HttpMethod.GET.equals(request.getMethod())) {
if (request.getMethod() != HttpMethod.GET) {
sendMethodNotAllowed(response, HttpMethod.GET);
return;
}

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.
@@ -250,7 +250,7 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
try {
HttpMethod supportedMethod = transportType.getHttpMethod();
if (supportedMethod != request.getMethod()) {
if (HttpMethod.OPTIONS == request.getMethod() && transportType.supportsCors()) {
if (request.getMethod() == HttpMethod.OPTIONS && transportType.supportsCors()) {
if (checkOrigin(request, response, HttpMethod.OPTIONS, supportedMethod)) {
response.setStatusCode(HttpStatus.NO_CONTENT);
addCacheHeaders(response);