Currently ForwardRequestPostProcessor
uses the forwarded URL only to set the servletPath of the mock request, which means requestUri
and servletPath
are out of sync.
This hasn't been reported as an issue since UrlPathHelper
falls back on the servletPath
if it doesn't match the requestURI
but that's not really correct behavior, and causes issues in more modern setups like parsed patterns where we rely mainly on the requestURI
and only check the servletPath
if a Servlet prefix mapping can be confirmed with Servlet 4.0.
In the absence of a Servlet container, i.e. with mock request and response, there is actually no good way to take a forwardedUrl
and break it down into contextPath
, servletPath
, and pathInfo
. At best, we can assert that the forwarded URL does start with the same contextPath
, but otherwise break it down into contextPath
+ servletPath
.
This was uncovered while working on #28607.