All Implemented Interfaces:
Serializable, Servlet, ServletConfig, ResourceFactory

public class I2PDefaultServletextends DefaultServlet
Extends DefaultServlet to set locale for the displayed time of directory listings, to prevent leaking of the locale.
See Also:
  • Field Details

    • _contextHandler

      private ContextHandler _contextHandler
      The context handler, a shadow of a private field in the superclass.
    • _dirAllowed

      private boolean _dirAllowed
      Whether directory listing is allowed
    • _etags

      private boolean _etags
      Whether ETags are enabled
    • _resourceBase

      private Resource _resourceBase
      The resource base
    • _stylesheet

      private Resource _stylesheet
      The stylesheet resource
    • FORMAT

      private static final String FORMAT
      Date format for directory listing
      See Also:
    • LAST_MODIFIED_FORMAT

      private static final String LAST_MODIFIED_FORMAT
      Date format for Last-Modified header
      See Also:
  • Constructor Details

    • I2PDefaultServlet

      public I2PDefaultServlet()
      Constructor. Jetty instantiates the servlet itself and init() picks up the context handler and resource base, so a bare instance is the starting state.
  • Method Details

    • init

      public void init() throws UnavailableException
      Overridden to save local copies of dirAllowed, locale, resourceBase, and stylesheet. Calls super.
      Overrides:
      init in class DefaultServlet
      Throws:
      UnavailableException
    • initContextHandler

      protected ContextHandler initContextHandler(ServletContext servletContext)
      Overridden to save the result Calls super.
      Overrides:
      initContextHandler in class DefaultServlet
    • getInitBoolean

      private boolean getInitBoolean(String name, boolean dft)
      Reads an init parameter as a true/false value, copied from Tomcat's DefaultServlet unchanged.
      Parameters:
      name - the parameter's name
      dft - 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 from DefaultServlet.java. Overridden to set the Locale for the dates. Get the resource list as a HTML directory listing.
      Overrides:
      sendDirectory in class DefaultServlet
      Throws:
      IOException
    • getListHTML

      private static String getListHTML(Resource res, String base, boolean parent) throws IOException
      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 listing
      base - The base URL
      parent - 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

      private static String hrefEncodeURI(String raw)
      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

      private static String deTag(String raw)
      Copied unchanged from Resource.java
      Parameters:
      raw - the text to strip XML markup from
      Returns:
      the sanitized text, safe to embed in the directory listing
    • doGet

      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      Handle GET request, set Last-Modified header, delegate to super.
      Overrides:
      doGet in class DefaultServlet
      Throws:
      ServletException
      IOException
    • getResource

      public Resource getResource(String path)
      The cached resource for the path, if any.
      Specified by:
      getResource in interface ResourceFactory
      Overrides:
      getResource in class DefaultServlet
      Returns:
      the resource for the path, or the first extension alias that resolves when the aliases init parameter is "true", else null