|
32 | 32 |
|
33 | 33 | import org.springframework.http.HttpHeaders;
|
34 | 34 | import org.springframework.http.HttpStatus;
|
| 35 | +import org.springframework.http.server.PathContainer; |
35 | 36 | import org.springframework.http.server.RequestPath;
|
36 | 37 | import org.springframework.lang.Nullable;
|
37 | 38 | import org.springframework.util.LinkedMultiValueMap;
|
@@ -94,7 +95,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
|
94 | 95 | path = ServletRequestPathUtils.parseAndCache(request);
|
95 | 96 | }
|
96 | 97 | for (Map.Entry<Handler, List<PathPattern>> entry : this.handlers.entrySet()) {
|
97 |
| - if (!entry.getKey().canHandle(request)) { |
| 98 | + if (!entry.getKey().canHandle(request, path)) { |
98 | 99 | continue;
|
99 | 100 | }
|
100 | 101 | for (PathPattern pattern : entry.getValue()) {
|
@@ -247,7 +248,7 @@ private interface Handler {
|
247 | 248 | /**
|
248 | 249 | * Whether the handler handles the given request.
|
249 | 250 | */
|
250 |
| - boolean canHandle(HttpServletRequest request); |
| 251 | + boolean canHandle(HttpServletRequest request, RequestPath path); |
251 | 252 |
|
252 | 253 | /**
|
253 | 254 | * Handle the request, possibly delegating to the rest of the filter chain.
|
@@ -276,8 +277,9 @@ protected AbstractTrailingSlashHandler(@Nullable Consumer<HttpServletRequest> in
|
276 | 277 | }
|
277 | 278 |
|
278 | 279 | @Override
|
279 |
| - public boolean canHandle(HttpServletRequest request) { |
280 |
| - return request.getRequestURI().endsWith("/"); |
| 280 | + public boolean canHandle(HttpServletRequest request, RequestPath path) { |
| 281 | + List<PathContainer.Element> elements = path.elements(); |
| 282 | + return (!elements.isEmpty() && elements.get(elements.size() - 1).value().equals("/")); |
281 | 283 | }
|
282 | 284 |
|
283 | 285 | @Override
|
|
0 commit comments