|
|
|
@ -33,8 +33,8 @@ import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory that can be used to create a {@link ServerWebExchangeMatcher} for static resources in
|
|
|
|
|
* commonly used locations.
|
|
|
|
|
* Factory that can be used to create a {@link ServerWebExchangeMatcher} for static
|
|
|
|
|
* resources in commonly used locations.
|
|
|
|
|
*
|
|
|
|
|
* @author Madhura Bhave
|
|
|
|
|
* @since 2.0.0
|
|
|
|
@ -45,10 +45,11 @@ public final class StaticResourceRequest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a matcher that includes all commonly used {@link StaticResourceLocation Locations}. The
|
|
|
|
|
* {@link StaticResourceServerWebExchange#excluding(StaticResourceLocation, StaticResourceLocation...) excluding}
|
|
|
|
|
* method can be used to remove specific locations if required. For example:
|
|
|
|
|
* <pre class="code">
|
|
|
|
|
* Returns a matcher that includes all commonly used {@link StaticResourceLocation
|
|
|
|
|
* Locations}. The
|
|
|
|
|
* {@link StaticResourceServerWebExchange#excluding(StaticResourceLocation, StaticResourceLocation...)
|
|
|
|
|
* excluding} method can be used to remove specific locations if required. For
|
|
|
|
|
* example: <pre class="code">
|
|
|
|
|
* StaticResourceRequest.toCommonLocations().excluding(StaticResourceLocation.CSS)
|
|
|
|
|
* </pre>
|
|
|
|
|
* @return the configured {@link ServerWebExchangeMatcher}
|
|
|
|
@ -58,33 +59,36 @@ public final class StaticResourceRequest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a matcher that includes the specified {@link StaticResourceLocation Locations}. For
|
|
|
|
|
* example: <pre class="code">
|
|
|
|
|
* Returns a matcher that includes the specified {@link StaticResourceLocation
|
|
|
|
|
* Locations}. For example: <pre class="code">
|
|
|
|
|
* to(StaticResourceLocation.CSS, StaticResourceLocation.JAVA_SCRIPT)
|
|
|
|
|
* </pre>
|
|
|
|
|
* @param first the first location to include
|
|
|
|
|
* @param rest additional locations to include
|
|
|
|
|
* @return the configured {@link ServerWebExchangeMatcher}
|
|
|
|
|
*/
|
|
|
|
|
public static StaticResourceServerWebExchange to(StaticResourceLocation first, StaticResourceLocation... rest) {
|
|
|
|
|
public static StaticResourceServerWebExchange to(StaticResourceLocation first,
|
|
|
|
|
StaticResourceLocation... rest) {
|
|
|
|
|
return to(EnumSet.of(first, rest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a matcher that includes the specified {@link StaticResourceLocation Locations}. For
|
|
|
|
|
* example: <pre class="code">
|
|
|
|
|
* Returns a matcher that includes the specified {@link StaticResourceLocation
|
|
|
|
|
* Locations}. For example: <pre class="code">
|
|
|
|
|
* to(locations)
|
|
|
|
|
* </pre>
|
|
|
|
|
* @param locations the locations to include
|
|
|
|
|
* @return the configured {@link ServerWebExchangeMatcher}
|
|
|
|
|
*/
|
|
|
|
|
public static StaticResourceServerWebExchange to(Set<StaticResourceLocation> locations) {
|
|
|
|
|
public static StaticResourceServerWebExchange to(
|
|
|
|
|
Set<StaticResourceLocation> locations) {
|
|
|
|
|
Assert.notNull(locations, "Locations must not be null");
|
|
|
|
|
return new StaticResourceServerWebExchange(new LinkedHashSet<>(locations));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server web exchange matcher used to match against resource {@link StaticResourceLocation Locations}.
|
|
|
|
|
* The server web exchange matcher used to match against resource
|
|
|
|
|
* {@link StaticResourceLocation Locations}.
|
|
|
|
|
*/
|
|
|
|
|
public final static class StaticResourceServerWebExchange
|
|
|
|
|
implements ServerWebExchangeMatcher {
|
|
|
|
@ -102,7 +106,8 @@ public final class StaticResourceRequest {
|
|
|
|
|
* @param rest additional locations to exclude
|
|
|
|
|
* @return a new {@link StaticResourceServerWebExchange}
|
|
|
|
|
*/
|
|
|
|
|
public StaticResourceServerWebExchange excluding(StaticResourceLocation first, StaticResourceLocation... rest) {
|
|
|
|
|
public StaticResourceServerWebExchange excluding(StaticResourceLocation first,
|
|
|
|
|
StaticResourceLocation... rest) {
|
|
|
|
|
return excluding(EnumSet.of(first, rest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,7 +117,8 @@ public final class StaticResourceRequest {
|
|
|
|
|
* @param locations the locations to exclude
|
|
|
|
|
* @return a new {@link StaticResourceServerWebExchange}
|
|
|
|
|
*/
|
|
|
|
|
public StaticResourceServerWebExchange excluding(Set<StaticResourceLocation> locations) {
|
|
|
|
|
public StaticResourceServerWebExchange excluding(
|
|
|
|
|
Set<StaticResourceLocation> locations) {
|
|
|
|
|
Assert.notNull(locations, "Locations must not be null");
|
|
|
|
|
Set<StaticResourceLocation> subset = new LinkedHashSet<>(this.locations);
|
|
|
|
|
subset.removeAll(locations);
|
|
|
|
@ -130,10 +136,10 @@ public final class StaticResourceRequest {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
|
|
|
|
OrServerWebExchangeMatcher matcher = new OrServerWebExchangeMatcher(getDelegateMatchers());
|
|
|
|
|
OrServerWebExchangeMatcher matcher = new OrServerWebExchangeMatcher(
|
|
|
|
|
getDelegateMatchers());
|
|
|
|
|
return matcher.matches(exchange);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|