Separate out URL path parsing in PathContainer

PathContainer now has separate parsePath and parseUrlPath methods each
creating PathSegment and UrlPathSegment respectively.
This commit is contained in:
Rossen Stoyanchev
2017-07-11 10:06:15 +02:00
parent 1d201a55db
commit 0e370e0703
18 changed files with 149 additions and 103 deletions

View File

@@ -19,9 +19,7 @@ package org.springframework.web.reactive.function.server;
import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.Principal;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -80,7 +78,7 @@ public interface ServerRequest {
* Return the request path as {@code PathContainer}.
*/
default PathContainer pathContainer() {
return PathContainer.parse(path(), StandardCharsets.UTF_8);
return PathContainer.parseUrlPath(path());
}
/**

View File

@@ -16,7 +16,6 @@
package org.springframework.web.reactive.resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -174,7 +173,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
int queryIndex = getQueryIndex(requestUrl);
String lookupPath = requestUrl.substring(0, queryIndex);
String query = requestUrl.substring(queryIndex);
PathContainer parsedLookupPath = PathContainer.parse(lookupPath, StandardCharsets.UTF_8);
PathContainer parsedLookupPath = PathContainer.parseUrlPath(lookupPath);
return getForLookupPath(parsedLookupPath).map(resolvedPath ->
request.getPath().contextPath().value() + resolvedPath + query);
}

View File

@@ -83,7 +83,7 @@ public class ResourceHandlerRegistryTests {
public void mapPathToLocation() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
PathContainer.parse("/testStylesheet.css", StandardCharsets.UTF_8));
PathContainer.parsePath("/testStylesheet.css"));
ResourceWebHandler handler = getHandler("/resources/**");
handler.handle(exchange).block(Duration.ofSeconds(5));

View File

@@ -16,7 +16,6 @@
package org.springframework.web.reactive.resource;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
@@ -75,7 +74,7 @@ public class ResourceUrlProviderTests {
@Test
public void getStaticResourceUrl() {
PathContainer path = PathContainer.parse("/resources/foo.css", StandardCharsets.UTF_8);
PathContainer path = PathContainer.parsePath("/resources/foo.css");
String url = this.urlProvider.getForLookupPath(path).block(Duration.ofSeconds(5));
assertEquals("/resources/foo.css", url);
}
@@ -105,7 +104,7 @@ public class ResourceUrlProviderTests {
resolvers.add(new PathResourceResolver());
this.handler.setResourceResolvers(resolvers);
PathContainer path = PathContainer.parse("/resources/foo.css", StandardCharsets.UTF_8);
PathContainer path = PathContainer.parsePath("/resources/foo.css");
String url = this.urlProvider.getForLookupPath(path).block(Duration.ofSeconds(5));
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
}
@@ -127,7 +126,7 @@ public class ResourceUrlProviderTests {
this.handlerMap.put("/resources/*.css", otherHandler);
this.urlProvider.registerHandlers(this.handlerMap);
PathContainer path = PathContainer.parse("/resources/foo.css", StandardCharsets.UTF_8);
PathContainer path = PathContainer.parsePath("/resources/foo.css");
String url = this.urlProvider.getForLookupPath(path).block(Duration.ofSeconds(5));
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
}

View File

@@ -553,7 +553,7 @@ public class ResourceWebHandlerTests {
private void setPathWithinHandlerMapping(ServerWebExchange exchange, String path) {
exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
PathContainer.parse(path, StandardCharsets.UTF_8));
PathContainer.parsePath(path));
}
private long resourceLastModified(String resourceName) throws IOException {