net.i2p.i2ptunnel

## Class I2PTunnelHTTPServer

- java.lang.Object
- - net.i2p.util.EventDispatcherImpl
  - - net.i2p.i2ptunnel.I2PTunnelTask
    - - net.i2p.i2ptunnel.I2PTunnelServer
      - - net.i2p.i2ptunnel.I2PTunnelHTTPServer

- All Implemented Interfaces:
    Runnable, EventDispatcher
  Direct Known Subclasses:
    I2PTunnelHTTPBidirServer

      public class I2PTunnelHTTPServer
      extends I2PTunnelServer

  HTTP server tunnel that filters headers and provides compression.

  Extends I2PTunnelServer to filter HTTP headers from client to server, replacing the Host header with configured value. Compresses HTTP message body and sets Content-Encoding: x-i2p-gzip when browser requests Accept-Encoding: x-i2p-gzip.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_POST_BAN_TIME` all of these in SECONDS
    `static int` | `DEFAULT_POST_MAX`
    `static int` | `DEFAULT_POST_TOTAL_BAN_TIME`
    `static int` | `DEFAULT_POST_TOTAL_MAX`
    `static int` | `DEFAULT_POST_WINDOW`
    `(package private) static String` | `ERR_FORBIDDEN`
    `(package private) static String` | `ERR_NOT_FOUND`
    `protected static String` | `ERR_REQUEST_TIMEOUT`
    `static String` | `OPT_ADD_RESPONSE_HEADER_ALLOW`
    `static String` | `OPT_ADD_RESPONSE_HEADER_CACHE_CONTROL`
    `static String` | `OPT_ADD_RESPONSE_HEADER_NOSNIFF`
    `static String` | `OPT_ADD_RESPONSE_HEADER_REFERRER_POLICY`
    `static String` | `OPT_KEEPALIVE`
    `static String` | `OPT_POST_BAN_TIME`
    `static String` | `OPT_POST_MAX`
    `static String` | `OPT_POST_TOTAL_BAN_TIME`
    `static String` | `OPT_POST_TOTAL_MAX`
    `static String` | `OPT_POST_WINDOW`
    `static String` | `OPT_REJECT_INPROXY`
    `static String` | `OPT_REJECT_REFERER`
    `static String` | `OPT_REJECT_USER_AGENTS`
    `static String` | `OPT_USER_AGENTS`

    - ### Fields inherited from class net.i2p.i2ptunnel.I2PTunnelServer

      `__serverId, _clientExecutor, _log, bidir, i2pss, l, localPort, PROP_ALT_PKF, PROP_UNIQUE_LOCAL, PROP_USE_SSL, readTimeout, remoteHost, remotePort, slock, sockMgr, sslLock, task`

    - ### Fields inherited from class net.i2p.i2ptunnel.I2PTunnelTask

      `open, tunnel`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `I2PTunnelHTTPServer(InetAddress host, int port, File privkey, String privkeyname, String spoofHost, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`
    `I2PTunnelHTTPServer(InetAddress host, int port, InputStream privData, String privkeyname, String spoofHost, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`
    `I2PTunnelHTTPServer(InetAddress host, int port, String privData, String spoofHost, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) static void` | `addEntry(Map<String,List<String>> headers, String key, String value)` Add an entry to the multimap.
    `protected void` | `blockingHandle(I2PSocket socket)` Called by the thread pool of I2PSocket handlers
    `boolean` | `close(boolean forced)` Note that the tunnel can be reopened after this by calling startRunning().
    `protected static String` | `formatHeaders(Map<String,List<String>> headers, StringBuilder command)`
    `protected static String` | `formatHeadersCompact(Map<String,List<String>> headers, StringBuilder command)`
    `void` | `optionsUpdated(I2PTunnel tunnel)` Update the I2PSocketManager.
    `static Map<String,List<String>>` | `readHeaders(I2PSocket socket, InputStream in, StringBuilder command, Set<String> skipHeaders, I2PAppContext ctx, long initialTimeout)` From I2P to server: socket non-null, in null.
    `static Map<String,List<String>>` | `readHeaders(I2PSocket socket, InputStream in, StringBuilder command, String[] skipHeaders, I2PAppContext ctx, long initialTimeout)`
    `(package private) static void` | `setEntry(Map<String,List<String>> headers, String key, String value)` Remove the other matching entries and set this entry as the only one.
    `void` | `startRunning()` Start running the I2PTunnelServer.

    - ### Methods inherited from class net.i2p.i2ptunnel.I2PTunnelServer

      `destroy, getReadTimeout, getSocket, getSocket, getSocketString, run, setReadTimeout, shutdownAndAwaitTermination`

    - ### Methods inherited from class net.i2p.i2ptunnel.I2PTunnelTask

      `connected, disconnected, errorOccurred, getBooleanOption, getId, getTunnel, isOpen, reportAbuse, routerDisconnected, setId, setName, setTunnel, toString`

    - ### Methods inherited from class net.i2p.util.EventDispatcherImpl

      `attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValue`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_POST_BAN_TIME

          public static final int DEFAULT_POST_BAN_TIME

      all of these in SECONDS
      See Also:
        Constant Field Values

    - #### DEFAULT_POST_MAX

          public static final int DEFAULT_POST_MAX

      See Also:
        Constant Field Values

    - #### DEFAULT_POST_TOTAL_BAN_TIME

          public static final int DEFAULT_POST_TOTAL_BAN_TIME

      See Also:
        Constant Field Values

    - #### DEFAULT_POST_TOTAL_MAX

          public static final int DEFAULT_POST_TOTAL_MAX

      See Also:
        Constant Field Values

    - #### DEFAULT_POST_WINDOW

          public static final int DEFAULT_POST_WINDOW

      See Also:
        Constant Field Values

    - #### ERR_FORBIDDEN

          static final String ERR_FORBIDDEN

      See Also:
        Constant Field Values

    - #### ERR_NOT_FOUND

          static final String ERR_NOT_FOUND

      See Also:
        Constant Field Values

    - #### ERR_REQUEST_TIMEOUT

          protected static final String ERR_REQUEST_TIMEOUT

      See Also:
        Constant Field Values

    - #### OPT_ADD_RESPONSE_HEADER_ALLOW

          public static final String OPT_ADD_RESPONSE_HEADER_ALLOW

      See Also:
        Constant Field Values

    - #### OPT_ADD_RESPONSE_HEADER_CACHE_CONTROL

          public static final String OPT_ADD_RESPONSE_HEADER_CACHE_CONTROL

      See Also:
        Constant Field Values

    - #### OPT_ADD_RESPONSE_HEADER_NOSNIFF

          public static final String OPT_ADD_RESPONSE_HEADER_NOSNIFF

      See Also:
        Constant Field Values

    - #### OPT_ADD_RESPONSE_HEADER_REFERRER_POLICY

          public static final String OPT_ADD_RESPONSE_HEADER_REFERRER_POLICY

      See Also:
        Constant Field Values

    - #### OPT_KEEPALIVE

          public static final String OPT_KEEPALIVE

      See Also:
        Constant Field Values

    - #### OPT_POST_BAN_TIME

          public static final String OPT_POST_BAN_TIME

      See Also:
        Constant Field Values

    - #### OPT_POST_MAX

          public static final String OPT_POST_MAX

      See Also:
        Constant Field Values

    - #### OPT_POST_TOTAL_BAN_TIME

          public static final String OPT_POST_TOTAL_BAN_TIME

      See Also:
        Constant Field Values

    - #### OPT_POST_TOTAL_MAX

          public static final String OPT_POST_TOTAL_MAX

      See Also:
        Constant Field Values

    - #### OPT_POST_WINDOW

          public static final String OPT_POST_WINDOW

      See Also:
        Constant Field Values

    - #### OPT_REJECT_INPROXY

          public static final String OPT_REJECT_INPROXY

      See Also:
        Constant Field Values

    - #### OPT_REJECT_REFERER

          public static final String OPT_REJECT_REFERER

      See Also:
        Constant Field Values

    - #### OPT_REJECT_USER_AGENTS

          public static final String OPT_REJECT_USER_AGENTS

      See Also:
        Constant Field Values

    - #### OPT_USER_AGENTS

          public static final String OPT_USER_AGENTS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### I2PTunnelHTTPServer

          public I2PTunnelHTTPServer(InetAddress host,
                                     int port,
                                     File privkey,
                                     String privkeyname,
                                     String spoofHost,
                                     Logging l,
                                     EventDispatcher notifyThis,
                                     I2PTunnel tunnel)

    - #### I2PTunnelHTTPServer

          public I2PTunnelHTTPServer(InetAddress host,
                                     int port,
                                     InputStream privData,
                                     String privkeyname,
                                     String spoofHost,
                                     Logging l,
                                     EventDispatcher notifyThis,
                                     I2PTunnel tunnel)

    - #### I2PTunnelHTTPServer

          public I2PTunnelHTTPServer(InetAddress host,
                                     int port,
                                     String privData,
                                     String spoofHost,
                                     Logging l,
                                     EventDispatcher notifyThis,
                                     I2PTunnel tunnel)

  - ### Method Detail

    - #### addEntry

          static void addEntry(Map<String,List<String>> headers,
                               String key,
                               String value)

      Add an entry to the multimap.

    - #### blockingHandle

          protected void blockingHandle(I2PSocket socket)

      Called by the thread pool of I2PSocket handlers
      Overrides:
        `blockingHandle` in class `I2PTunnelServer`
      Parameters:
        `socket` - the incoming I2P connection from a remote peer; never null
      See Also:
        `I2PTunnelServer.getSocket(Hash, int)`, `I2PTunnelRunner`

    - #### close

          public boolean close(boolean forced)

      Description copied from class: `I2PTunnelServer`
      Note that the tunnel can be reopened after this by calling startRunning(). This does not release all resources. In particular, the I2PSocketManager remains and it may have timer threads that continue running. To release all resources permanently, call destroy().
      Overrides:
        `close` in class `I2PTunnelServer`
      Returns:
        true if the tunnel was closed successfully, false if connections exist and forced is false

    - #### formatHeaders

          protected static String formatHeaders(Map<String,List<String>> headers,
                                                StringBuilder command)

      Returns:
        the command followed by the header lines

    - #### formatHeadersCompact

          protected static String formatHeadersCompact(Map<String,List<String>> headers,
                                                       StringBuilder command)

      Returns:
        the command followed by the header lines (compact version for logging)

    - #### optionsUpdated

          public void optionsUpdated(I2PTunnel tunnel)

      Description copied from class: `I2PTunnelServer`
      Update the I2PSocketManager. And since 0.9.15, the target host and port.
      Overrides:
        `optionsUpdated` in class `I2PTunnelServer`

    - #### readHeaders

          public static Map<String,List<String>> readHeaders(I2PSocket socket,
                                                             InputStream in,
                                                             StringBuilder command,
                                                             Set<String> skipHeaders,
                                                             I2PAppContext ctx,
                                                             long initialTimeout)
                                                      throws IOException

      From I2P to server: socket non-null, in null. From server to I2P: socket null, in non-null. Note: This does not handle RFC 2616 header line splitting, which is obsoleted in RFC 7230.
      Parameters:
        `socket` - if null, use in as InputStream
        `in` - if null, use socket.getInputStream() as InputStream
        `command` - out parameter, first line
        `skipHeaders` - MUST be lower case
      Throws:
        `SocketTimeoutException` - if timeout is reached before newline
        `EOFException` - if EOF is reached before newline
        `LineTooLongException` - if one header too long, or too many headers, or total size too big
        `RequestTooLongException` - if too long
        `BadRequestException` - on bad headers
        `IOException` - on other errors in the underlying stream

    - #### readHeaders

          public static Map<String,List<String>> readHeaders(I2PSocket socket,
                                                             InputStream in,
                                                             StringBuilder command,
                                                             String[] skipHeaders,
                                                             I2PAppContext ctx,
                                                             long initialTimeout)
                                                      throws IOException

      Throws:
        `IOException`

    - #### setEntry

          static void setEntry(Map<String,List<String>> headers,
                               String key,
                               String value)

      Remove the other matching entries and set this entry as the only one.

    - #### startRunning

          public void startRunning()

      Description copied from class: `I2PTunnelServer`
      Start running the I2PTunnelServer. Warning, blocks while connecting to router and building tunnels;
      Overrides:
        `startRunning` in class `I2PTunnelServer`