Adapt to trailing slashes no longer being matched by default

See gh-31563
This commit is contained in:
Andy Wilkinson
2022-07-07 14:14:05 +01:00
parent 97d96eebdf
commit e9136e023b
12 changed files with 79 additions and 18 deletions

View File

@@ -180,8 +180,9 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
private void registerLinksMapping() {
String path = this.endpointMapping.getPath();
String linksPath = StringUtils.hasLength(path) ? path : "/";
String[] produces = StringUtils.toStringArray(this.endpointMediaTypes.getProduced());
RequestMappingInfo mapping = RequestMappingInfo.paths(path).methods(RequestMethod.GET).produces(produces)
RequestMappingInfo mapping = RequestMappingInfo.paths(linksPath).methods(RequestMethod.GET).produces(produces)
.build();
LinksHandler linksHandler = getLinksHandler();
registerMapping(mapping, linksHandler,

View File

@@ -240,9 +240,11 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
}
private void registerLinksMapping() {
RequestMappingInfo mapping = RequestMappingInfo.paths(this.endpointMapping.createSubPath(""))
.methods(RequestMethod.GET).produces(this.endpointMediaTypes.getProduced().toArray(new String[0]))
.options(this.builderConfig).build();
String path = this.endpointMapping.getPath();
String linksPath = (StringUtils.hasLength(path)) ? this.endpointMapping.createSubPath("/") : "/";
RequestMappingInfo mapping = RequestMappingInfo.paths(linksPath).methods(RequestMethod.GET)
.produces(this.endpointMediaTypes.getProduced().toArray(new String[0])).options(this.builderConfig)
.build();
LinksHandler linksHandler = getLinksHandler();
registerMapping(mapping, linksHandler, ReflectionUtils.findMethod(linksHandler.getClass(), "links",
HttpServletRequest.class, HttpServletResponse.class));