net.i2p.i2ptunnel

## Class HttpHeaderFormatter

- java.lang.Object
- - net.i2p.i2ptunnel.HttpHeaderFormatter

-     public class HttpHeaderFormatter
      extends Object

  Utility class for formatting HTTP headers.

  This class provides static methods for formatting HTTP headers for both transmission and logging purposes. It handles the conversion of header maps to properly formatted HTTP header strings.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpHeaderFormatter()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `formatHeaders(Map<String,List<String>> headers, StringBuilder command)` Formats headers into an HTTP request/response string.
    `static String` | `formatHeadersCompact(Map<String,List<String>> headers, StringBuilder command)` Formats headers into a compact string for logging.
    `static String` | `getHostFromHeaders(String headers)` Extracts the Host header value from raw HTTP headers.

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

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

- - ### Constructor Detail

    - #### HttpHeaderFormatter

          public HttpHeaderFormatter()

  - ### Method Detail

    - #### formatHeaders

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

      Formats headers into an HTTP request/response string.

      This method takes a header map and formats it into a properly formatted HTTP header block suitable for transmission. The format is:

           REQUEST_LINE
           Header-Name: value
           ...

      Parameters:
        `headers` - the HTTP headers map (header name to list of values)
        `command` - the request/response command line (e.g., "GET / HTTP/1.1")
      Returns:
        the formatted HTTP headers as a string

    - #### formatHeadersCompact

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

      Formats headers into a compact string for logging.

      This method creates a compact, human-readable representation of HTTP headers suitable for logging. It filters out sensitive or verbose headers like cookies, authentication headers, and excessive request details.

      The following are excluded from the output:

      - Headers containing "desthash", "destb64", "dnt"
      - Connection, Accept, Cookie, Pragma, Cache-Control headers
      - Referer header with full URL
      - Content-Length: 0
      - User-Agent containing "MYOB"
      - HEAD requests (headers only)

      Long request URLs containing "peer_id" are truncated.

      Parameters:
        `headers` - the HTTP headers map
        `command` - the request command line
      Returns:
        a compact string representation suitable for logging

    - #### getHostFromHeaders

          public static String getHostFromHeaders(String headers)

      Extracts the Host header value from raw HTTP headers.

      This method parses raw HTTP header text and extracts the value of the Host header. If the host contains a port number, it is stripped and only the hostname is returned.

      Parameters:
        `headers` - the raw HTTP headers as a string
      Returns:
        the hostname from the Host header, or null if not found