net.i2p.i2ptunnel

## Class MimeTypeDetector

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

-     public class MimeTypeDetector
      extends Object

  Utility class for MIME type detection based on URL file extensions.

  This class provides static methods to determine the MIME type of a resource based on its file extension. It is used by I2PTunnelHTTPServer to set appropriate Content-Type headers for responses and to determine which security headers and cache policies should be applied.

  The MIME type detection follows the Common MIME types specification as documented at MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MimeTypeDetector()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `detectMimeType(String url)` Detects the MIME type based on a URL's file extension.
    `static boolean` | `isCustomWhitelist(String mimeType)` Checks if a MIME type requires custom security headers.
    `static boolean` | `isImmutableCache(String mimeType)` Checks if a MIME type should use immutable cache control headers.

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

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

- - ### Constructor Detail

    - #### MimeTypeDetector

          public MimeTypeDetector()

  - ### Method Detail

    - #### detectMimeType

          public static String detectMimeType(String url)

      Detects the MIME type based on a URL's file extension.

      If the URL contains a query string, it is stripped before checking the extension. If no matching extension is found or the URL is null, returns "application/octet-stream" as a safe default.

      Parameters:
        `url` - the URL or file path to detect the MIME type for; may be null
      Returns:
        the detected MIME type, or "application/octet-stream" if unknown

    - #### isCustomWhitelist

          public static boolean isCustomWhitelist(String mimeType)

      Checks if a MIME type requires custom security headers.

      MIME types in this whitelist (text/html, application/xhtml+xml, etc.) will receive additional security headers such as Referrer-Policy and Allow headers.

      Parameters:
        `mimeType` - the MIME type to check; may be null
      Returns:
        true if the MIME type requires security headers, false otherwise

    - #### isImmutableCache

          public static boolean isImmutableCache(String mimeType)

      Checks if a MIME type should use immutable cache control headers.

      MIME types that match known immutable content patterns (images, fonts, video, audio, etc.) will receive "Cache-Control: private, max-age=31536000, immutable" to enable long-term caching.

      Parameters:
        `mimeType` - the MIME type to check; may be null
      Returns:
        true if the MIME type should use immutable cache control, false otherwise