42
42
public final class RequestMethodsRequestCondition extends AbstractRequestCondition <RequestMethodsRequestCondition > {
43
43
44
44
/** Per HTTP method cache to return ready instances from getMatchingCondition. */
45
- private static final Map <String , RequestMethodsRequestCondition > requestMethodConditionCache ;
45
+ private static final Map <HttpMethod , RequestMethodsRequestCondition > requestMethodConditionCache ;
46
46
47
47
static {
48
48
requestMethodConditionCache = new HashMap <>(RequestMethod .values ().length );
49
49
for (RequestMethod method : RequestMethod .values ()) {
50
- requestMethodConditionCache .put (method .name (), new RequestMethodsRequestCondition (method ));
50
+ requestMethodConditionCache .put (
51
+ HttpMethod .valueOf (method .name ()), new RequestMethodsRequestCondition (method ));
51
52
}
52
53
}
53
54
@@ -123,7 +124,7 @@ public RequestMethodsRequestCondition getMatchingCondition(ServerWebExchange exc
123
124
}
124
125
return this ;
125
126
}
126
- return matchRequestMethod (exchange .getRequest ().getMethodValue ());
127
+ return matchRequestMethod (exchange .getRequest ().getMethod ());
127
128
}
128
129
129
130
/**
@@ -137,20 +138,20 @@ private RequestMethodsRequestCondition matchPreFlight(ServerHttpRequest request)
137
138
return this ;
138
139
}
139
140
HttpMethod expectedMethod = request .getHeaders ().getAccessControlRequestMethod ();
140
- return expectedMethod != null ? matchRequestMethod (expectedMethod . name () ) : null ;
141
+ return expectedMethod != null ? matchRequestMethod (expectedMethod ) : null ;
141
142
}
142
143
143
144
@ Nullable
144
- private RequestMethodsRequestCondition matchRequestMethod (@ Nullable String httpMethod ) {
145
- if (httpMethod ! = null ) {
146
- for ( RequestMethod method : getMethods ()) {
147
- if ( httpMethod . matches ( method . name ())) {
148
- return requestMethodConditionCache . get ( method .name ());
149
- }
150
- }
151
- if ( HttpMethod . HEAD . matches ( httpMethod ) && getMethods (). contains ( RequestMethod . GET )) {
152
- return requestMethodConditionCache . get ( HttpMethod . GET . name ());
153
- }
145
+ private RequestMethodsRequestCondition matchRequestMethod (@ Nullable HttpMethod httpMethod ) {
146
+ if (httpMethod = = null ) {
147
+ return null ;
148
+ }
149
+ RequestMethod requestMethod = RequestMethod . valueOf ( httpMethod .name ());
150
+ if ( getMethods (). contains ( requestMethod )) {
151
+ return requestMethodConditionCache . get ( httpMethod );
152
+ }
153
+ if ( requestMethod . equals ( RequestMethod . HEAD ) && getMethods (). contains ( RequestMethod . GET )) {
154
+ return requestMethodConditionCache . get ( HttpMethod . GET );
154
155
}
155
156
return null ;
156
157
}
0 commit comments