Encapsulate choice of URI encoding within RequestPath
Currently the URI path is always treated as UTF-8 so we can eliminate the encoding parameter from RequestPath#parse.
This commit is contained in:
@@ -61,7 +61,7 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest {
|
||||
*/
|
||||
public AbstractServerHttpRequest(URI uri, String contextPath, HttpHeaders headers) {
|
||||
this.uri = uri;
|
||||
this.path = new DefaultRequestPath(uri, contextPath, StandardCharsets.UTF_8);
|
||||
this.path = RequestPath.parse(uri, contextPath);
|
||||
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.http.server.reactive;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@@ -40,8 +39,8 @@ class DefaultRequestPath implements RequestPath {
|
||||
private final PathContainer pathWithinApplication;
|
||||
|
||||
|
||||
DefaultRequestPath(URI uri, @Nullable String contextPath, Charset charset) {
|
||||
this.fullPath = PathContainer.parse(uri.getRawPath(), charset);
|
||||
DefaultRequestPath(URI uri, @Nullable String contextPath) {
|
||||
this.fullPath = PathContainer.parse(uri.getRawPath(), StandardCharsets.UTF_8);
|
||||
this.contextPath = initContextPath(this.fullPath, contextPath);
|
||||
this.pathWithinApplication = extractPathWithinApplication(this.fullPath, this.contextPath);
|
||||
}
|
||||
@@ -86,7 +85,6 @@ class DefaultRequestPath implements RequestPath {
|
||||
|
||||
// PathContainer methods..
|
||||
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return this.fullPath.value();
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.http.server.reactive;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -107,14 +106,14 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
|
||||
@Nullable
|
||||
private RequestPath getRequestPathToUse(@Nullable URI uriToUse) {
|
||||
if (uriToUse == null) {
|
||||
if (this.contextPath == null) {
|
||||
return null;
|
||||
}
|
||||
if (uriToUse == null && this.contextPath == null) {
|
||||
return null;
|
||||
}
|
||||
else if (uriToUse == null) {
|
||||
return new DefaultRequestPath(this.delegate.getPath(), this.contextPath);
|
||||
}
|
||||
else {
|
||||
return new DefaultRequestPath(uriToUse, this.contextPath, StandardCharsets.UTF_8);
|
||||
return RequestPath.parse(uriToUse, this.contextPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.http.server.reactive;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Represents the complete path for a request.
|
||||
@@ -41,11 +42,12 @@ public interface RequestPath extends PathContainer {
|
||||
*/
|
||||
PathContainer pathWithinApplication();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code RequestPath} with the given parameters.
|
||||
*/
|
||||
static RequestPath create(URI uri, String contextPath, Charset charset) {
|
||||
return new DefaultRequestPath(uri, contextPath, charset);
|
||||
static RequestPath parse(URI uri, @Nullable String contextPath) {
|
||||
return new DefaultRequestPath(uri, contextPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -261,12 +261,11 @@ public class PathPattern implements Comparable<PathPattern> {
|
||||
* @return the subset of the path that is matched by pattern or "" if none of it is matched by pattern elements
|
||||
*/
|
||||
public PathContainer extractPathWithinPattern(PathContainer path) {
|
||||
// TODO: implement extractPathWithinPattern for PathContainer
|
||||
String result = extractPathWithinPattern(path.value());
|
||||
return PathContainer.parse(result, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
// TODO: implement extractPathWithinPattern natively for PathContainer
|
||||
|
||||
private String extractPathWithinPattern(String path) {
|
||||
// assert this.matches(path)
|
||||
PathElement elem = head;
|
||||
|
||||
Reference in New Issue
Block a user