Description
Brian Clozel opened SPR-14544 and commented
Proposed changes
- No "?" or "**" allowed within the pattern:
"/te?t" or "/user/**/something"
(/) Yes
- Allow "{*foobar}" and "/**" at the end of the pattern to allow multiple segment matching until the end of the path:
"/files/{*path}"
(/) Yes
- Not supporting "*" in patterns and ensure use of named tokens like "{name}" in all cases:
"/user/*/repositories" becomes "/user/{name}/repositories"
(x) Those are interchangeable
- Clarify that multiple tokens should be allowed within one segment only if separated by a literal
"/user/{id}_{name}/
(/) Yes
These are relatively straight forward changes that would allow creating a grammar and a state machine for parsing patterns. Also, ensuring single segment tokens could help with creating a more efficient matching algorithm.
Additional changes for discussion
The following makes things a bit more complex and I'm not sure it's as useful but worth considering.
Keep constraints within the pattern or externalize those?
(x) Rejected because there is no tangible benefit besides readability and even that is subjective.
// keep everything within the pattern
@RequestMapping("/user/{id:[\\d\\.]+}")
// externalized constraints in method params: http headers, request params, etc
@RequestMapping(path="/user/{id}")
String handler(@PathVariable(constraint="[\\d\\.]+") id, @RequestParam (required=true) param)
Add a new constraint based on Host
Quite useful for routers, applications managing several domains or sub-domains.
Since you can map several domains on PWS, this is quite useful.
We can also define those as patterns like "{subdomain}.example.org"
Have default values for Path variables
(x) Rejected because it creates multiple mappings (one with and one without), it does not work unless it's in the last segment, and arguably it should be expressed as a request parameter since the route does not match.
// In case the page path var is empty, instead of declaring a separate route
@RequestMapping(path="/blog/{page}")
String handler(@PathVariable(default="1") page)
Affects: 5.0 M1
Issue Links:
- Improve nested routes API [SPR-14954] #19521 Improve nested routes API ("is depended on by")
- PathPatternParser#parse method failed with java.lang.IndexOutOfBoundsException [SPR-15246] #19811 PathPatternParser#parse method failed with java.lang.IndexOutOfBoundsException
- Polish PathPattern parser [SPR-15531] #20090 Polish PathPattern parser
- Wildcard mapping for path segments at the end of a @RequestMapping [SPR-14193] #18766 Wildcard mapping for path segments at the end of a
@RequestMapping
("supersedes")
2 votes, 8 watchers