java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.eclipse.jetty.servlet.DefaultServlet
net.i2p.servlet.I2PDefaultServlet
- All Implemented Interfaces:
Serializable, Servlet, ServletConfig, ResourceFactory
Extends DefaultServlet to set locale for the displayed time of directory listings, to prevent leaking of the locale.
- See Also:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCompares files in directory listing, directories before files.Field Summary
FieldsModifier and TypeFieldDescriptionprivate ContextHandlerThe context handler, a shadow of a private field in the superclass.private booleanWhether directory listing is allowedprivate booleanWhether ETags are enabledprivate ResourceThe resource baseprivate ResourceThe stylesheet resourceprivate static final StringDate format for directory listingprivate static final StringDate format for Last-Modified headerConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static StringCopied unchanged from Resource.javaprotected voiddoGet(HttpServletRequest request, HttpServletResponse response) Handle GET request, set Last-Modified header, delegate to super.private booleangetInitBoolean(String name, boolean dft) Reads an init parameter as a true/false value, copied from Tomcat's DefaultServlet unchanged.private static StringgetListHTML(Resource res, String base, boolean parent) Copied and modified from Resource.java Modified to set the Locale for the dates.getResource(String path) The cached resource for the path, if any.private static StringhrefEncodeURI(String raw) Copied unchanged from Resource.java Encode any characters that could break the URI string in an HREF.voidinit()Overridden to save local copies of dirAllowed, locale, resourceBase, and stylesheet.protected ContextHandlerinitContextHandler(ServletContext servletContext) Overridden to save the result Calls super.protected voidsendDirectory(HttpServletRequest request, HttpServletResponse response, Resource resource, String pathInContext) Copied and modified fromDefaultServlet.java.Methods inherited from class DefaultServlet
destroy, doOptions, doPost, doTrace, getInitParameter, isGzippedContent, passConditionalHeaders, putHeaders, sendData, sendWelcomeMethods inherited from class HttpServlet
doDelete, doHead, doPut, getLastModified, service, serviceMethods inherited from class GenericServlet
getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
Field Details
_contextHandler
The context handler, a shadow of a private field in the superclass._dirAllowed
private boolean _dirAllowedWhether directory listing is allowed_etags
private boolean _etagsWhether ETags are enabled_resourceBase
The resource base_stylesheet
The stylesheet resourceFORMAT
LAST_MODIFIED_FORMAT
Date format for Last-Modified header- See Also:
Constructor Details
I2PDefaultServlet
public I2PDefaultServlet()Constructor. Jetty instantiates the servlet itself andinit()picks up the context handler and resource base, so a bare instance is the starting state.
Method Details
init
Overridden to save local copies of dirAllowed, locale, resourceBase, and stylesheet. Calls super.- Overrides:
initin classDefaultServlet- Throws:
UnavailableException
initContextHandler
Overridden to save the result Calls super.- Overrides:
initContextHandlerin classDefaultServlet
getInitBoolean
Reads an init parameter as a true/false value, copied from Tomcat's DefaultServlet unchanged.- Parameters:
name- the parameter's namedft- the value to use when it is not set- Returns:
- the parameter's value, or the default
sendDirectory
protected void sendDirectory(HttpServletRequest request, HttpServletResponse response, Resource resource, String pathInContext) throws IOException Copied and modified fromDefaultServlet.java. Overridden to set the Locale for the dates. Get the resource list as a HTML directory listing.- Overrides:
sendDirectoryin classDefaultServlet- Throws:
IOException
getListHTML
Copied and modified from Resource.java Modified to set the Locale for the dates. Get the resource list as a HTML directory listing.- Parameters:
res- the directory resource to render as a listingbase- The base URLparent- True if the parent directory should be included- Returns:
- String of HTML
- Throws:
IOException- declared on the copied method, but every call that throws it is caught here
hrefEncodeURI
Copied unchanged from Resource.java Encode any characters that could break the URI string in an HREF. Such as <a href="/path/to;<script>Window.alert("XSS"+'%20'+"here");</script>">Link</a> The above example would parse incorrectly on various browsers as the "<" or '"' characters would end the href attribute value string prematurely.- Parameters:
raw- the raw data- Returns:
- the defanged text.
deTag
doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException Handle GET request, set Last-Modified header, delegate to super.- Overrides:
doGetin classDefaultServlet- Throws:
ServletExceptionIOException
getResource
The cached resource for the path, if any.- Specified by:
getResourcein interfaceResourceFactory- Overrides:
getResourcein classDefaultServlet- Returns:
- the resource for the path, or the first extension alias that resolves when the aliases init parameter is "true", else null