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

@@ -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<>(Arrays.asList(httpMethods)));
response.getHeaders().setAllow(new LinkedHashSet<>(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", StandardCharsets.UTF_8));
@@ -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.
@@ -252,7 +252,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);