@@ -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
/**
@@ -142,10 +143,6 @@ public MatchResult matcher(HttpServletRequest request) {
142
143
return (info != null ) ? MatchResult .match (info .getUriVariables ()) : MatchResult .notMatch ();
143
144
}
144
145
145
- void setMethod (RequestMatcher method ) {
146
- this .method = method ;
147
- }
148
-
149
146
private PathContainer getPathContainer (HttpServletRequest request ) {
150
147
RequestPath path ;
151
148
if (ServletRequestPathUtils .hasParsedRequestPath (request )) {
@@ -320,11 +317,8 @@ public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String pat
320
317
Assert .notNull (path , "pattern cannot be null" );
321
318
Assert .isTrue (path .startsWith ("/" ), "pattern must start with a /" );
322
319
PathPattern pathPattern = this .parser .parse (this .basePath + path );
323
- PathPatternRequestMatcher requestMatcher = new PathPatternRequestMatcher (pathPattern );
324
- if (method != null ) {
325
- requestMatcher .setMethod (new HttpMethodRequestMatcher (method ));
326
- }
327
- return requestMatcher ;
320
+ return new PathPatternRequestMatcher (pathPattern ,
321
+ (method != null ) ? new HttpMethodRequestMatcher (method ) : AnyRequestMatcher .INSTANCE );
328
322
}
329
323
330
324
}
0 commit comments