Package com.google.gerrit.httpd.raw
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ResourceServlet
(com.google.common.cache.Cache<Path, ResourceServlet.Resource> cache, boolean refresh) protected
ResourceServlet
(com.google.common.cache.Cache<Path, ResourceServlet.Resource> cache, boolean refresh, boolean cacheOnClient) -
Method Summary
Modifier and TypeMethodDescriptionprotected static String
contentType
(String name) protected void
doGet
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) protected FileTime
protected abstract Path
getResourcePath
(String pathInfo) Get the resource path on the filesystem that should be served for this request.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.protected boolean
shouldProcessResourceBeforeServe
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp, Path p) Indicates that resource requires some processing before being served.Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
-
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
-
getResourcePath
Get the resource path on the filesystem that should be served for this request.- Parameters:
pathInfo
- result ofHttpServletRequest.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 requestrsp
- the HTTP servlet responsep
- 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 requestrsp
- the HTTP servlet response
-
getLastModifiedTime
- Throws:
IOException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws IOException - Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
IOException
-