From b377965572fe8a735c1a1675073ee8b0ddbef722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Mon, 11 Dec 2023 22:10:56 +0100 Subject: [PATCH] Issue #11040 Register custom URI scheme in PathResource when necessary --- .../jetty/util/resource/PathResource.java | 19 ++++++++++++++----- .../resource/ResourceFactoryInternals.java | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java index 405e246a33c4..ac4e1f6ee879 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java @@ -40,11 +40,7 @@ public class PathResource extends Resource { private static final Logger LOG = LoggerFactory.getLogger(PathResource.class); - public static Index SUPPORTED_SCHEMES = new Index.Builder() - .caseSensitive(false) - .with("file") - .with("jrt") - .build(); + public static Index SUPPORTED_SCHEMES = initSupportedSchemes(null); // The path object represented by this instance private final Path path; @@ -541,4 +537,17 @@ public String toString() { return this.uri.toASCIIString(); } + + static Index initSupportedSchemes(String extraScheme) + { + Index.Builder builder = new Index.Builder() + .caseSensitive(false) + .with("file") + .with("jrt"); + if (extraScheme != null) { + builder = builder.with(extraScheme); + } + + return builder.build(); + } } diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactoryInternals.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactoryInternals.java index a870ae70596c..5bc9bec312e0 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactoryInternals.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactoryInternals.java @@ -76,7 +76,9 @@ class ResourceFactoryInternals resourceFactory = url.toString().contains("!/") ? mountedPathResourceFactory : pathResourceFactory; } - RESOURCE_FACTORIES.put(url.getProtocol(), resourceFactory); + String protocol = url.getProtocol(); + PathResource.SUPPORTED_SCHEMES = PathResource.initSupportedSchemes(protocol); + RESOURCE_FACTORIES.put(protocol, resourceFactory); } }