@@ -55,7 +55,7 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
55
55
56
56
private final PathPattern pattern ;
57
57
58
- private RequestMatcher method = AnyRequestMatcher . INSTANCE ;
58
+ private final RequestMatcher method ;
59
59
60
60
/**
61
61
* Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}.
@@ -64,8 +64,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
64
64
* </p>
65
65
* @param pattern the pattern used to match
66
66
*/
67
- private PathPatternRequestMatcher (PathPattern pattern ) {
67
+ private PathPatternRequestMatcher (PathPattern pattern , RequestMatcher method ) {
68
68
this .pattern = pattern ;
69
+ this .method = method ;
69
70
}
70
71
71
72
/**
@@ -108,10 +109,6 @@ public MatchResult matcher(HttpServletRequest request) {
108
109
return (info != null ) ? MatchResult .match (info .getUriVariables ()) : MatchResult .notMatch ();
109
110
}
110
111
111
- void setMethod (RequestMatcher method ) {
112
- this .method = method ;
113
- }
114
-
115
112
private PathContainer getPathContainer (HttpServletRequest request ) {
116
113
RequestPath path ;
117
114
if (ServletRequestPathUtils .hasParsedRequestPath (request )) {
@@ -286,11 +283,8 @@ public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String pat
286
283
Assert .notNull (path , "pattern cannot be null" );
287
284
Assert .isTrue (path .startsWith ("/" ), "pattern must start with a /" );
288
285
PathPattern pathPattern = this .parser .parse (this .basePath + path );
289
- PathPatternRequestMatcher requestMatcher = new PathPatternRequestMatcher (pathPattern );
290
- if (method != null ) {
291
- requestMatcher .setMethod (new HttpMethodRequestMatcher (method ));
292
- }
293
- return requestMatcher ;
286
+ return new PathPatternRequestMatcher (pathPattern ,
287
+ (method != null ) ? new HttpMethodRequestMatcher (method ) : AnyRequestMatcher .INSTANCE );
294
288
}
295
289
296
290
}
0 commit comments