Consistent HttpMethod identity comparisons
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.servlet.mvc.condition;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -27,17 +26,8 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -63,7 +53,7 @@ public class RequestMethodsRequestConditionTests {
|
||||
public void getMatchingConditionWithEmptyConditions() {
|
||||
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
|
||||
for (RequestMethod method : RequestMethod.values()) {
|
||||
if (!OPTIONS.equals(method)) {
|
||||
if (method != OPTIONS) {
|
||||
HttpServletRequest request = new MockHttpServletRequest(method.name(), "");
|
||||
assertNotNull(condition.getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -26,7 +23,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -63,6 +59,8 @@ import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link RequestMappingInfoHandlerMapping}.
|
||||
@@ -157,9 +155,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
// SPR-9603
|
||||
|
||||
@Test(expected = HttpMediaTypeNotAcceptableException.class)
|
||||
@Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-9603
|
||||
public void getHandlerRequestMethodMatchFalsePositive() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/users");
|
||||
request.addHeader("Accept", "application/xml");
|
||||
@@ -167,9 +163,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
this.handlerMapping.getHandler(request);
|
||||
}
|
||||
|
||||
// SPR-8462
|
||||
|
||||
@Test
|
||||
@Test // SPR-8462
|
||||
public void getHandlerMediaTypeNotSupported() throws Exception {
|
||||
testHttpMediaTypeNotSupportedException("/person/1");
|
||||
testHttpMediaTypeNotSupportedException("/person/1/");
|
||||
@@ -197,18 +191,14 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
// SPR-8462
|
||||
|
||||
@Test
|
||||
@Test // SPR-8462
|
||||
public void getHandlerMediaTypeNotAccepted() throws Exception {
|
||||
testHttpMediaTypeNotAcceptableException("/persons");
|
||||
testHttpMediaTypeNotAcceptableException("/persons/");
|
||||
testHttpMediaTypeNotAcceptableException("/persons.json");
|
||||
}
|
||||
|
||||
// SPR-12854
|
||||
|
||||
@Test
|
||||
@Test // SPR-12854
|
||||
public void getHandlerUnsatisfiedServletRequestParameterException() throws Exception {
|
||||
try {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/params");
|
||||
@@ -275,10 +265,8 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
assertEquals("2", uriVariables.get("path2"));
|
||||
}
|
||||
|
||||
// SPR-9098
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Test // SPR-9098
|
||||
public void handleMatchUriTemplateVariablesDecode() {
|
||||
RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");
|
||||
@@ -502,6 +490,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Controller
|
||||
private static class UserController {
|
||||
@@ -515,6 +504,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TestRequestMappingInfoHandlerMapping extends RequestMappingInfoHandlerMapping {
|
||||
|
||||
public void registerHandler(Object handler) {
|
||||
|
||||
Reference in New Issue
Block a user