Class ResourceHandler

  • All Implemented Interfaces:
    Handler, HandlerContainer, ResourceService.WelcomeFactory, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.resource.ResourceFactory

    public class ResourceHandler
    extends HandlerWrapper
    implements org.eclipse.jetty.util.resource.ResourceFactory, ResourceService.WelcomeFactory
    Resource Handler. This handle will serve static content and handle If-Modified-Since headers. No caching is done. Requests for resources that do not exist are let pass (Eg no 404's).
    • Constructor Detail

      • ResourceHandler

        public ResourceHandler​(ResourceService resourceService)
      • ResourceHandler

        public ResourceHandler()
    • Method Detail

      • getBaseResource

        public org.eclipse.jetty.util.resource.Resource getBaseResource()
        Returns:
        Returns the resourceBase.
      • getCacheControl

        public String getCacheControl()
        Returns:
        the cacheControl header to set on all static content.
      • getGzipEquivalentFileExtensions

        public List<String> getGzipEquivalentFileExtensions()
        Returns:
        file extensions that signify that a file is gzip compressed. Eg ".svgz"
      • getMimeTypes

        public org.eclipse.jetty.http.MimeTypes getMimeTypes()
      • getMinAsyncContentLength

        @Deprecated
        public int getMinAsyncContentLength()
        Deprecated.
        Get the minimum content length for async handling.
        Returns:
        The minimum size in bytes of the content before asynchronous handling is used, or -1 for no async handling or 0 (default) for using ServletResponse.getBufferSize() as the minimum length.
      • getMinMemoryMappedContentLength

        @Deprecated
        public int getMinMemoryMappedContentLength()
        Deprecated.
        Get minimum memory mapped file content length.
        Returns:
        the minimum size in bytes of a file resource that will be served using a memory mapped buffer, or -1 (default) for no memory mapped buffers.
      • getResource

        public org.eclipse.jetty.util.resource.Resource getResource​(String path)
        Specified by:
        getResource in interface org.eclipse.jetty.util.resource.ResourceFactory
      • getResourceBase

        public String getResourceBase()
        Returns:
        Returns the base resource as a string.
      • getStylesheet

        public org.eclipse.jetty.util.resource.Resource getStylesheet()
        Returns:
        Returns the stylesheet as a Resource.
      • getWelcomeFiles

        public String[] getWelcomeFiles()
      • isAcceptRanges

        public boolean isAcceptRanges()
        Returns:
        If true, range requests and responses are supported
      • isDirAllowed

        public boolean isDirAllowed()
        Returns:
        If true, directory listings are returned if no welcome file is found. Else 403 Forbidden.
      • isDirectoriesListed

        public boolean isDirectoriesListed()
        Get the directory option.
        Returns:
        true if directories are listed.
      • isEtags

        public boolean isEtags()
        Returns:
        True if ETag processing is done
      • isGzip

        @Deprecated
        public boolean isGzip()
        Deprecated.
        Returns:
        If set to true, then static content will be served as gzip content encoded if a matching resource is found ending with ".gz"
      • getPrecompressedFormats

        public org.eclipse.jetty.http.CompressedContentFormat[] getPrecompressedFormats()
        Returns:
        Precompressed resources formats that can be used to serve compressed variant of resources.
      • isPathInfoOnly

        public boolean isPathInfoOnly()
        Returns:
        true, only the path info will be applied to the resourceBase
      • isRedirectWelcome

        public boolean isRedirectWelcome()
        Returns:
        If true, welcome files are redirected rather than forwarded to.
      • setAcceptRanges

        public void setAcceptRanges​(boolean acceptRanges)
        Parameters:
        acceptRanges - If true, range requests and responses are supported
      • setBaseResource

        public void setBaseResource​(org.eclipse.jetty.util.resource.Resource base)
        Parameters:
        base - The resourceBase to server content from. If null the context resource base is used.
      • setCacheControl

        public void setCacheControl​(String cacheControl)
        Parameters:
        cacheControl - the cacheControl header to set on all static content.
      • setDirAllowed

        public void setDirAllowed​(boolean dirAllowed)
        Parameters:
        dirAllowed - If true, directory listings are returned if no welcome file is found. Else 403 Forbidden.
      • setDirectoriesListed

        public void setDirectoriesListed​(boolean directory)
        Set the directory.
        Parameters:
        directory - true if directories are listed.
      • setEtags

        public void setEtags​(boolean etags)
        Parameters:
        etags - True if ETag processing is done
      • setGzip

        @Deprecated
        public void setGzip​(boolean gzip)
        Deprecated.
        Parameters:
        gzip - If set to true, then static content will be served as gzip content encoded if a matching resource is found ending with ".gz"
      • setGzipEquivalentFileExtensions

        public void setGzipEquivalentFileExtensions​(List<String> gzipEquivalentFileExtensions)
        Parameters:
        gzipEquivalentFileExtensions - file extensions that signify that a file is gzip compressed. Eg ".svgz"
      • setPrecompressedFormats

        public void setPrecompressedFormats​(org.eclipse.jetty.http.CompressedContentFormat[] precompressedFormats)
        Parameters:
        precompressedFormats - The list of precompresed formats to serve in encoded format if matching resource found. For example serve gzip encoded file if ".gz" suffixed resource is found.
      • setMimeTypes

        public void setMimeTypes​(org.eclipse.jetty.http.MimeTypes mimeTypes)
      • setMinAsyncContentLength

        @Deprecated
        public void setMinAsyncContentLength​(int minAsyncContentLength)
        Deprecated.
        Set the minimum content length for async handling.
        Parameters:
        minAsyncContentLength - The minimum size in bytes of the content before asynchronous handling is used, or -1 for no async handling or 0 for using ServletResponse.getBufferSize() as the minimum length.
      • setMinMemoryMappedContentLength

        @Deprecated
        public void setMinMemoryMappedContentLength​(int minMemoryMappedFileSize)
        Deprecated.
        Set minimum memory mapped file content length.
        Parameters:
        minMemoryMappedFileSize - the minimum size in bytes of a file resource that will be served using a memory mapped buffer, or -1 for no memory mapped buffers.
      • setPathInfoOnly

        public void setPathInfoOnly​(boolean pathInfoOnly)
        Parameters:
        pathInfoOnly - true, only the path info will be applied to the resourceBase
      • setRedirectWelcome

        public void setRedirectWelcome​(boolean redirectWelcome)
        Parameters:
        redirectWelcome - If true, welcome files are redirected rather than forwarded to. redirection is always used if the ResourceHandler is not scoped by a ContextHandler
      • setResourceBase

        public void setResourceBase​(String resourceBase)
        Parameters:
        resourceBase - The base resource as a string.
      • setStylesheet

        public void setStylesheet​(String stylesheet)
        Parameters:
        stylesheet - The location of the stylesheet to be used as a String.
      • setWelcomeFiles

        public void setWelcomeFiles​(String[] welcomeFiles)