Skip to content

Commit

Permalink
Issue #10852 - Add ResourceHandler.setUseFileMapping(boolean) feature (
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime authored Dec 15, 2023
1 parent 35af2d8 commit 15c3369
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ResourceHandler extends Handler.Wrapper
private Resource _styleSheet;
private MimeTypes _mimeTypes;
private List<String> _welcomes = List.of("index.html");
private boolean _useFileMapping = true;

public ResourceHandler()
{
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
_useFileMapping = useFileMapping;
}

public void setWelcomeMode(ResourceService.WelcomeMode welcomeMode)
{
_resourceService.setWelcomeMode(welcomeMode);
Expand Down

0 comments on commit 15c3369

Please sign in to comment.