Class ResourceServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.google.gerrit.httpd.raw.ResourceServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
SiteStaticDirectoryServlet

public abstract class ResourceServlet extends javax.servlet.http.HttpServlet
Base class for serving static resources.

Supports caching, ETags, basic content type detection, and limited gzip compression.

See Also:
  • Constructor Details

    • ResourceServlet

      protected ResourceServlet(com.google.common.cache.Cache<Path,ResourceServlet.Resource> cache, boolean refresh)
    • ResourceServlet

      protected ResourceServlet(com.google.common.cache.Cache<Path,ResourceServlet.Resource> cache, boolean refresh, boolean cacheOnClient)
  • Method Details

    • contentType

      protected static String contentType(String name)
    • getResourcePath

      protected abstract Path getResourcePath(String pathInfo) throws IOException
      Get the resource path on the filesystem that should be served for this request.
      Parameters:
      pathInfo - result of HttpServletRequest.getPathInfo().
      Returns:
      path where static content can be found.
      Throws:
      IOException - if an error occurred resolving the resource.
    • shouldProcessResourceBeforeServe

      protected boolean shouldProcessResourceBeforeServe(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp, Path p)
      Indicates that resource requires some processing before being served.

      If true, the caching headers in response are set to not cache. Additionally, streaming option is disabled.

      Parameters:
      req - the HTTP servlet request
      rsp - the HTTP servlet response
      p - URL path
      Returns:
      true if the processResourceBeforeServe(HttpServletRequest, HttpServletResponse, Resource) should be called.
    • processResourceBeforeServe

      protected ResourceServlet.Resource processResourceBeforeServe(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp, ResourceServlet.Resource resource)
      Edits the resource before adding it to the response.
      Parameters:
      req - the HTTP servlet request
      rsp - the HTTP servlet response
    • getLastModifiedTime

      protected FileTime getLastModifiedTime(Path p) throws IOException
      Throws:
      IOException
    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws IOException
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Throws:
      IOException