java.lang.Object
net.i2p.i2ptunnel.localServer.LocalHTTPServer

public abstract class LocalHTTPServerextends Object
Very simple web server.

Serve local files in the docs/ directory, for CSS and images in error pages, using the reserved address proxy.i2p (similar to p.p in privoxy). This solves the problems with including links to the router console, as assuming the router console is at 127.0.0.1 leads to broken links if it isn't.

  • Field Details

  • Constructor Details

    • LocalHTTPServer

      public LocalHTTPServer()
      Construct the tunnel's local HTTP server.
  • Method Details

    • serveLocalFile

      public static void serveLocalFile(I2PAppContext context, I2PSocketManager sockMgr, OutputStream out, String method, String targetRequest, String query, String proxyNonce, boolean allowGzip) throws IOException
      Very simple web server.

      Serve local files in the docs/ directory, for CSS and images in error pages, using the reserved address proxy.i2p (similar to p.p in privoxy). This solves the problems with including links to the router console, as assuming the router console is at 127.0.0.1 leads to broken links if it isn't.

      Ignore all request headers (If-Modified-Since, etc.)

      There is basic protection here - FileUtil.readFile(String, String, OutputStream) prevents traversal above the base directory - but inproxy/gateway ops would be wise to block proxy.i2p to prevent exposing the docs/ directory or perhaps other issues through uncaught vulnerabilities. Restrict to the /themes/ directory for now.

      Parameters:
      context - the I2P app context
      sockMgr - only for /b32, otherwise ignored
      out - the output stream
      method - the HTTP method
      targetRequest - decoded path only, non-null
      query - raw (encoded), may be null
      proxyNonce - the proxy nonce
      allowGzip - whether gzip is allowed
      Throws:
      IOException - if an I/O error occurs
    • writeRedirectPage

      private static void writeRedirectPage(OutputStream out, boolean success, String host, String book, String url) throws IOException
      Send the redirect result page to the browser.
      Parameters:
      out - the stream to write the HTTP response to
      success - true if the entry was saved to the addressbook, false to report the failure
      host - the host that was added, shown decoded as an IDN in the page title
      book - the addressbook file changed, e.g. "hosts.txt", shown by translated name
      url - the URL to redirect the browser to
      Throws:
      IOException - if writing to the browser stream fails
    • writeB32RedirectPage

      private static void writeB32RedirectPage(OutputStream out, String host, String url) throws IOException
      Write a blinding info redirect page to the output stream.
      Parameters:
      out - the output stream to write to
      host - the blinded host
      url - the URL to redirect to
      Throws:
      IOException - if an I/O error occurs
    • decodeQuery

      private static Map<String,String> decodeQuery(String query)
      Parse an encoded query. Only supports ONE value per key.
      Parameters:
      query - an ENCODED query, non-null
      Returns:
      map of DECODED keys to DECODED values, non-null. Values may be empty.
    • decode

      public static String decode(String s)
      Decode percent-encoded (%xx) strings.
      Parameters:
      s - the encoded string
      Returns:
      the decoded string
    • _t

      protected static String _t(String key)
      Translate a message key using the proxy message bundle.
      Parameters:
      key - the message key to translate
      Returns:
      the translated string
    • _t

      protected static String _t(String key, Object o)
      Translate a message key with one parameter.
      Parameters:
      key - the message key to translate
      o - the parameter to substitute for {0}
      Returns:
      the translated string
    • _t

      protected static String _t(String key, Object o, Object o2)
      Translate a message key with two parameters.
      Parameters:
      key - the message key to translate
      o - the parameter to substitute for {0}
      o2 - the parameter to substitute for {1}
      Returns:
      the translated string