1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -164,17 +164,18 @@ protected String getDefaultEncoding() {
164
164
* @see #getPathWithinApplication
165
165
*/
166
166
public String getLookupPathForRequest (HttpServletRequest request ) {
167
+ String pathWithinApp = getPathWithinApplication (request );
167
168
// Always use full path within current servlet context?
168
169
if (this .alwaysUseFullPath ) {
169
- return getPathWithinApplication ( request ) ;
170
+ return pathWithinApp ;
170
171
}
171
172
// Else, use path within current servlet mapping if applicable
172
- String rest = getPathWithinServletMapping (request );
173
+ String rest = getPathWithinServletMapping (request , pathWithinApp );
173
174
if (StringUtils .hasLength (rest )) {
174
175
return rest ;
175
176
}
176
177
else {
177
- return getPathWithinApplication ( request ) ;
178
+ return pathWithinApp ;
178
179
}
179
180
}
180
181
@@ -198,6 +199,18 @@ public String getLookupPathForRequest(HttpServletRequest request, @Nullable Stri
198
199
return getLookupPathForRequest (request );
199
200
}
200
201
202
+ /**
203
+ * Return the path within the servlet mapping for the given request,
204
+ * i.e. the part of the request's URL beyond the part that called the servlet,
205
+ * or "" if the whole URL has been used to identify the servlet.
206
+ * @param request current HTTP request
207
+ * @return the path within the servlet mapping, or ""
208
+ * @see #getPathWithinServletMapping(HttpServletRequest, String)
209
+ */
210
+ public String getPathWithinServletMapping (HttpServletRequest request ) {
211
+ return getPathWithinServletMapping (request , getPathWithinApplication (request ));
212
+ }
213
+
201
214
/**
202
215
* Return the path within the servlet mapping for the given request,
203
216
* i.e. the part of the request's URL beyond the part that called the servlet,
@@ -209,11 +222,12 @@ public String getLookupPathForRequest(HttpServletRequest request, @Nullable Stri
209
222
* <p>E.g.: servlet mapping = "/test"; request URI = "/test" -> "".
210
223
* <p>E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "".
211
224
* @param request current HTTP request
225
+ * @param pathWithinApp a precomputed path within the application
212
226
* @return the path within the servlet mapping, or ""
227
+ * @since 5.2.9
213
228
* @see #getLookupPathForRequest
214
229
*/
215
- public String getPathWithinServletMapping (HttpServletRequest request ) {
216
- String pathWithinApp = getPathWithinApplication (request );
230
+ protected String getPathWithinServletMapping (HttpServletRequest request , String pathWithinApp ) {
217
231
String servletPath = getServletPath (request );
218
232
String sanitizedPathWithinApp = getSanitizedPath (pathWithinApp );
219
233
String path ;
0 commit comments