|
25 | 25 | import javax.servlet.http.HttpServletRequest;
|
26 | 26 |
|
27 | 27 | import org.springframework.http.HttpHeaders;
|
| 28 | +import org.springframework.http.HttpMethod; |
28 | 29 | import org.springframework.web.bind.annotation.RequestMethod;
|
29 | 30 | import org.springframework.web.cors.CorsUtils;
|
30 | 31 |
|
@@ -103,7 +104,6 @@ public RequestMethodsRequestCondition combine(RequestMethodsRequestCondition oth
|
103 | 104 | */
|
104 | 105 | @Override
|
105 | 106 | public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) {
|
106 |
| - |
107 | 107 | if (CorsUtils.isPreFlightRequest(request)) {
|
108 | 108 | return matchPreFlight(request);
|
109 | 109 | }
|
@@ -131,30 +131,21 @@ private RequestMethodsRequestCondition matchPreFlight(HttpServletRequest request
|
131 | 131 | return matchRequestMethod(expectedMethod);
|
132 | 132 | }
|
133 | 133 |
|
134 |
| - private RequestMethodsRequestCondition matchRequestMethod(String httpMethod) { |
135 |
| - RequestMethod requestMethod = getRequestMethod(httpMethod); |
136 |
| - if (requestMethod != null) { |
| 134 | + private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) { |
| 135 | + HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue); |
| 136 | + if (httpMethod != null) { |
137 | 137 | for (RequestMethod method : getMethods()) {
|
138 |
| - if (method.equals(requestMethod)) { |
| 138 | + if (httpMethod.matches(method.name())) { |
139 | 139 | return new RequestMethodsRequestCondition(method);
|
140 | 140 | }
|
141 | 141 | }
|
142 |
| - if (RequestMethod.HEAD.equals(requestMethod) && getMethods().contains(RequestMethod.GET)) { |
| 142 | + if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) { |
143 | 143 | return HEAD_CONDITION;
|
144 | 144 | }
|
145 | 145 | }
|
146 | 146 | return null;
|
147 | 147 | }
|
148 | 148 |
|
149 |
| - private RequestMethod getRequestMethod(String httpMethod) { |
150 |
| - try { |
151 |
| - return RequestMethod.valueOf(httpMethod); |
152 |
| - } |
153 |
| - catch (IllegalArgumentException ex) { |
154 |
| - return null; |
155 |
| - } |
156 |
| - } |
157 |
| - |
158 | 149 | /**
|
159 | 150 | * Returns:
|
160 | 151 | * <ul>
|
|
0 commit comments