Class TryFilesFilter
java.lang.Object
org.eclipse.jetty.ee9.fcgi.proxy.TryFilesFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
Inspired by nginx's try_files functionality.
This filter accepts the files init-param as a list of space-separated
file URIs. The special token $path represents the current request URL's
path (the portion after the context path).
Typical example of how this filter can be configured is the following:
<filter>
<filter-name>try_files</filter-name>
<filter-class>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter</filter-class>
<init-param>
<param-name>files</param-name>
<param-value>/maintenance.html $path /index.php?p=$path</param-value>
</init-param>
</filter>
For a request such as /context/path/to/resource.ext, this filter will
try to serve the /maintenance.html file if it finds it; failing that,
it will try to serve the /path/to/resource.ext file if it finds it;
failing that it will forward the request to /index.php?p=/path/to/resource.ext.
The last file URI specified in the list is therefore the "fallback" to which the request
is forwarded to in case no previous files can be found.
The files are resolved using ServletContext.getResource(String) to make sure
that only files visible to the application are served.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()voiddoFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) protected voidfallback(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain, String fallback) voidinit(jakarta.servlet.FilterConfig config)
-
Field Details
-
FILES_INIT_PARAM
- See Also:
-
-
Constructor Details
-
TryFilesFilter
public TryFilesFilter()
-
-
Method Details
-
init
public void init(jakarta.servlet.FilterConfig config) throws jakarta.servlet.ServletException - Specified by:
initin interfacejakarta.servlet.Filter- Throws:
jakarta.servlet.ServletException
-
doFilter
public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException - Specified by:
doFilterin interfacejakarta.servlet.Filter- Throws:
IOExceptionjakarta.servlet.ServletException
-
fallback
protected void fallback(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain, String fallback) throws IOException, jakarta.servlet.ServletException - Throws:
IOExceptionjakarta.servlet.ServletException
-
destroy
public void destroy()- Specified by:
destroyin interfacejakarta.servlet.Filter
-