public class MimeTypeDetector extends Object
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 and Description |
|---|
MimeTypeDetector() |
| 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.
|
public static String detectMimeType(String url)
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.
url - the URL or file path to detect the MIME type for; may be nullpublic static boolean isCustomWhitelist(String mimeType)
MIME types in this whitelist (text/html, application/xhtml+xml, etc.) will receive additional security headers such as Referrer-Policy and Allow headers.
mimeType - the MIME type to check; may be nullpublic static boolean isImmutableCache(String mimeType)
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.
mimeType - the MIME type to check; may be null