Leverage PathPatternParser in CORS configuration source

Previously `UrlBasedCorsConfigurationSource` was relying on
`PathMatcher` implementations for matching incoming request lookup paths
with the configured path patterns for CORS configuration.

This commit replaces the use of `PathMatcher` with a `PathPatternParser`
that parses the string patterns into `PathPattenr` instances and allows
for faster matching against lookup paths.

Issue: SPR-15688
This commit is contained in:
Brian Clozel
2017-07-04 15:44:15 +02:00
parent fd1859c34c
commit 9c93521512
3 changed files with 26 additions and 46 deletions

View File

@@ -21,6 +21,7 @@ import org.junit.Test;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -33,7 +34,8 @@ import static org.junit.Assert.assertNull;
*/
public class UrlBasedCorsConfigurationSourceTests {
private final UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
private final UrlBasedCorsConfigurationSource configSource
= new UrlBasedCorsConfigurationSource(new PathPatternParser());
@Test
@@ -54,9 +56,4 @@ public class UrlBasedCorsConfigurationSourceTests {
assertEquals(config, this.configSource.getCorsConfiguration(exchange));
}
@Test(expected = UnsupportedOperationException.class)
public void unmodifiableConfigurationsMap() {
this.configSource.getCorsConfigurations().put("/**", new CorsConfiguration());
}
}