Expose RequestPath in ServerHttpRequest
The new structured getPath() method replaces the existing getContextPath() + getPathWithinApplication(). Issue: SPR-15648
This commit is contained in:
@@ -100,7 +100,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
|
||||
|
||||
@Override
|
||||
public Mono<Object> getHandlerInternal(ServerWebExchange exchange) {
|
||||
String lookupPath = exchange.getRequest().getPathWithinApplication();
|
||||
String lookupPath = exchange.getRequest().getPath().pathWithinApplication().value();
|
||||
Object handler;
|
||||
try {
|
||||
handler = lookupHandler(lookupPath, exchange);
|
||||
|
||||
@@ -166,7 +166,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
private int getLookupPathIndex(ServerWebExchange exchange) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String requestPath = request.getURI().getPath();
|
||||
String lookupPath = exchange.getRequest().getPathWithinApplication();
|
||||
String lookupPath = exchange.getRequest().getPath().pathWithinApplication().value();
|
||||
return requestPath.indexOf(lookupPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
return this;
|
||||
}
|
||||
|
||||
String lookupPath = exchange.getRequest().getPathWithinApplication();
|
||||
String lookupPath = exchange.getRequest().getPath().pathWithinApplication().value();
|
||||
List<String> matches = getMatchingPatterns(lookupPath);
|
||||
|
||||
return matches.isEmpty() ? null :
|
||||
@@ -243,7 +243,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(PatternsRequestCondition other, ServerWebExchange exchange) {
|
||||
String lookupPath = exchange.getRequest().getPathWithinApplication();
|
||||
String lookupPath = exchange.getRequest().getPath().pathWithinApplication().value();
|
||||
Comparator<String> patternComparator = this.pathMatcher.getPatternComparator(lookupPath);
|
||||
Iterator<String> iterator = this.patterns.iterator();
|
||||
Iterator<String> iteratorOther = other.patterns.iterator();
|
||||
|
||||
@@ -257,7 +257,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
*/
|
||||
@Override
|
||||
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
|
||||
String lookupPath = exchange.getRequest().getPathWithinApplication();
|
||||
String lookupPath = exchange.getRequest().getPath().pathWithinApplication().value();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Looking up handler method for path " + lookupPath);
|
||||
}
|
||||
|
||||
@@ -202,9 +202,11 @@ public class RedirectView extends AbstractUrlBasedView {
|
||||
String url = getUrl();
|
||||
Assert.state(url != null, "'url' not set");
|
||||
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
|
||||
StringBuilder targetUrl = new StringBuilder();
|
||||
if (isContextRelative() && url.startsWith("/")) {
|
||||
targetUrl.append(exchange.getRequest().getContextPath());
|
||||
targetUrl.append(request.getPath().contextPath().value());
|
||||
}
|
||||
targetUrl.append(url);
|
||||
|
||||
@@ -214,7 +216,7 @@ public class RedirectView extends AbstractUrlBasedView {
|
||||
}
|
||||
|
||||
if (isPropagateQuery()) {
|
||||
targetUrl = appendCurrentRequestQuery(targetUrl.toString(), exchange.getRequest());
|
||||
targetUrl = appendCurrentRequestQuery(targetUrl.toString(), request);
|
||||
}
|
||||
|
||||
String result = targetUrl.toString();
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.context.NoSuchMessageException;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
@@ -180,10 +181,10 @@ public class RequestContext {
|
||||
/**
|
||||
* Return the context path of the current web application. This is
|
||||
* useful for building links to other resources within the application.
|
||||
* <p>Delegates to {@link ServerHttpRequest#getContextPath()}.
|
||||
* <p>Delegates to {@link ServerHttpRequest#getPath()}.
|
||||
*/
|
||||
public String getContextPath() {
|
||||
return this.exchange.getRequest().getContextPath();
|
||||
return this.exchange.getRequest().getPath().contextPath().value();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +194,7 @@ public class RequestContext {
|
||||
* absolute path also URL-encoded accordingly
|
||||
*/
|
||||
public String getContextUrl(String relativeUrl) {
|
||||
String url = getContextPath() + relativeUrl;
|
||||
String url = StringUtils.applyRelativePath(getContextPath() + "/", relativeUrl);
|
||||
return getExchange().getResponse().encodeUrl(url);
|
||||
}
|
||||
|
||||
@@ -208,7 +209,7 @@ public class RequestContext {
|
||||
* absolute path also URL-encoded accordingly
|
||||
*/
|
||||
public String getContextUrl(String relativeUrl, Map<String, ?> params) {
|
||||
String url = getContextPath() + relativeUrl;
|
||||
String url = StringUtils.applyRelativePath(getContextPath() + "/", relativeUrl);
|
||||
UriTemplate template = new UriTemplate(url);
|
||||
url = template.expand(params).toASCIIString();
|
||||
return getExchange().getResponse().encodeUrl(url);
|
||||
|
||||
@@ -258,7 +258,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport
|
||||
* Use the request path the leading and trailing slash stripped.
|
||||
*/
|
||||
private String getDefaultViewName(ServerWebExchange exchange) {
|
||||
String path = exchange.getRequest().getPathWithinApplication();
|
||||
String path = exchange.getRequest().getPath().pathWithinApplication().value();
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user