Consistent and lenient HttpMethod resolution across all web modules

Issue: SPR-13776
This commit is contained in:
Juergen Hoeller
2015-12-09 12:26:44 +01:00
parent 34b596c6bf
commit 4261f34b63
29 changed files with 149 additions and 109 deletions

View File

@@ -231,7 +231,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
logger.trace("Processing request " + request.getURI() + " with headers=" + headers);
}
try {
if (!HttpMethod.GET.equals(request.getMethod())) {
if (HttpMethod.GET != request.getMethod()) {
response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
response.getHeaders().setAllow(Collections.singleton(HttpMethod.GET));
if (logger.isErrorEnabled()) {
@@ -320,8 +320,8 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
". Supported versions: " + Arrays.toString(getSupportedVersions()));
}
response.setStatusCode(HttpStatus.UPGRADE_REQUIRED);
response.getHeaders().put(WebSocketHttpHeaders.SEC_WEBSOCKET_VERSION,
Arrays.asList(StringUtils.arrayToCommaDelimitedString(getSupportedVersions())));
response.getHeaders().set(WebSocketHttpHeaders.SEC_WEBSOCKET_VERSION,
StringUtils.arrayToCommaDelimitedString(getSupportedVersions()));
}
/**

View File

@@ -544,7 +544,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 (HttpMethod.GET == request.getMethod()) {
addNoCacheHeaders(response);
if (checkOrigin(request, response)) {
response.getHeaders().setContentType(new MediaType("application", "json", UTF8_CHARSET));
@@ -554,7 +554,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
}
else if (HttpMethod.OPTIONS.equals(request.getMethod())) {
else if (HttpMethod.OPTIONS == request.getMethod()) {
if (checkOrigin(request, response)) {
addCacheHeaders(response);
response.setStatusCode(HttpStatus.NO_CONTENT);

View File

@@ -247,8 +247,8 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
try {
HttpMethod supportedMethod = transportType.getHttpMethod();
if (!supportedMethod.equals(request.getMethod())) {
if (HttpMethod.OPTIONS.equals(request.getMethod()) && transportType.supportsCors()) {
if (supportedMethod != request.getMethod()) {
if (HttpMethod.OPTIONS == request.getMethod() && transportType.supportsCors()) {
if (checkOrigin(request, response, HttpMethod.OPTIONS, supportedMethod)) {
response.setStatusCode(HttpStatus.NO_CONTENT);
addCacheHeaders(response);