Resolve ResourceUrlProvider from current request
This commit changes `ResourceTransformerSupport` to look for the `ResourceUrlProvider` in the current request if none is configured on the resource transformer itself. Issue: SPR-15369
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -144,7 +144,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
|||||||
return Mono.just(new LineOutput(info.getLine(), null));
|
return Mono.just(new LineOutput(info.getLine(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
String link = toAbsolutePath(info.getLine(), exchange.getRequest());
|
String link = toAbsolutePath(info.getLine(), exchange);
|
||||||
Mono<String> pathMono = resolveUrlPath(link, exchange, resource, chain)
|
Mono<String> pathMono = resolveUrlPath(link, exchange, resource, chain)
|
||||||
.doOnNext(path -> {
|
.doOnNext(path -> {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -103,7 +103,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
|
|||||||
.concatMap(segment -> {
|
.concatMap(segment -> {
|
||||||
String segmentContent = segment.getContent(fullContent);
|
String segmentContent = segment.getContent(fullContent);
|
||||||
if (segment.isLink() && !hasScheme(segmentContent)) {
|
if (segment.isLink() && !hasScheme(segmentContent)) {
|
||||||
String link = toAbsolutePath(segmentContent, exchange.getRequest());
|
String link = toAbsolutePath(segmentContent, exchange);
|
||||||
return resolveUrlPath(link, exchange, newResource, transformerChain)
|
return resolveUrlPath(link, exchange, newResource, transformerChain)
|
||||||
.defaultIfEmpty(segmentContent);
|
.defaultIfEmpty(segmentContent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -89,11 +89,11 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
|
|||||||
* The resulting path is also cleaned from sequences like "path/..".
|
* The resulting path is also cleaned from sequences like "path/..".
|
||||||
*
|
*
|
||||||
* @param path the relative path to transform
|
* @param path the relative path to transform
|
||||||
* @param request the referer request
|
* @param exchange the current exchange
|
||||||
* @return the absolute request path for the given resource path
|
* @return the absolute request path for the given resource path
|
||||||
*/
|
*/
|
||||||
protected String toAbsolutePath(String path, ServerHttpRequest request) {
|
protected String toAbsolutePath(String path, ServerWebExchange exchange) {
|
||||||
String requestPath = request.getURI().getPath();
|
String requestPath = exchange.getRequest().getURI().getPath();
|
||||||
String absolutePath = StringUtils.applyRelativePath(requestPath, path);
|
String absolutePath = StringUtils.applyRelativePath(requestPath, path);
|
||||||
return StringUtils.cleanPath(absolutePath);
|
return StringUtils.cleanPath(absolutePath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -38,15 +38,8 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
|
|||||||
/**
|
/**
|
||||||
* Configure a {@link ResourceUrlProvider} to use when resolving the public
|
* Configure a {@link ResourceUrlProvider} to use when resolving the public
|
||||||
* URL of links in a transformed resource (e.g. import links in a CSS file).
|
* URL of links in a transformed resource (e.g. import links in a CSS file).
|
||||||
* This is required only for links expressed as full paths, i.e. including
|
* This is required only for links expressed as full paths and not for
|
||||||
* context and servlet path, and not for relative links.
|
* relative links.
|
||||||
* <p>By default this property is not set. In that case if a
|
|
||||||
* {@code ResourceUrlProvider} is needed an attempt is made to find the
|
|
||||||
* {@code ResourceUrlProvider} exposed through the
|
|
||||||
* {@link org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor
|
|
||||||
* ResourceUrlProviderExposingInterceptor} (configured by default in the MVC
|
|
||||||
* Java config and XML namespace). Therefore explicitly configuring this
|
|
||||||
* property should not be needed in most cases.
|
|
||||||
* @param resourceUrlProvider the URL provider to use
|
* @param resourceUrlProvider the URL provider to use
|
||||||
*/
|
*/
|
||||||
public void setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider) {
|
public void setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider) {
|
||||||
@@ -96,7 +89,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
|
|||||||
* @return the absolute request path for the given resource path
|
* @return the absolute request path for the given resource path
|
||||||
*/
|
*/
|
||||||
protected String toAbsolutePath(String path, HttpServletRequest request) {
|
protected String toAbsolutePath(String path, HttpServletRequest request) {
|
||||||
String requestPath = this.getResourceUrlProvider().getUrlPathHelper().getRequestUri(request);
|
String requestPath = this.findResourceUrlProvider(request).getUrlPathHelper().getRequestUri(request);
|
||||||
String absolutePath = StringUtils.applyRelativePath(requestPath, path);
|
String absolutePath = StringUtils.applyRelativePath(requestPath, path);
|
||||||
return StringUtils.cleanPath(absolutePath);
|
return StringUtils.cleanPath(absolutePath);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user