diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java index 2bb442e021d..e7cce34d038 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java @@ -62,6 +62,7 @@ public class ResourceHandler extends Handler.Wrapper private Resource _styleSheet; private MimeTypes _mimeTypes; private List _welcomes = List.of("index.html"); + private boolean _useFileMapping = true; public ResourceHandler() { @@ -123,7 +124,8 @@ public HttpContent.Factory getHttpContentFactory() protected HttpContent.Factory newHttpContentFactory() { HttpContent.Factory contentFactory = new ResourceHttpContentFactory(ResourceFactory.of(getBaseResource()), getMimeTypes()); - contentFactory = new FileMappingHttpContentFactory(contentFactory); + if (isUseFileMapping()) + contentFactory = new FileMappingHttpContentFactory(contentFactory); contentFactory = new VirtualHttpContentFactory(contentFactory, getStyleSheet(), "text/css"); contentFactory = new PreCompressedHttpContentFactory(contentFactory, getPrecompressedFormats()); contentFactory = new ValidatingCachingHttpContentFactory(contentFactory, Duration.ofSeconds(1).toMillis(), getByteBufferPool()); @@ -241,6 +243,11 @@ public boolean isEtags() return _resourceService.isEtags(); } + public boolean isUseFileMapping() + { + return _useFileMapping; + } + /** * @return Precompressed resources formats that can be used to serve compressed variant of resources. */ @@ -351,6 +358,13 @@ public void setMimeTypes(MimeTypes mimeTypes) _mimeTypes = mimeTypes; } + public void setUseFileMapping(boolean useFileMapping) + { + if (isRunning()) + throw new IllegalStateException("Unable to set useFileMapping on started " + this.getClass().getSimpleName()); + _useFileMapping = useFileMapping; + } + public void setWelcomeMode(ResourceService.WelcomeMode welcomeMode) { _resourceService.setWelcomeMode(welcomeMode);