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
Field Summary
FieldsModifier and TypeFieldDescriptionMIME types that require security headers (Referrer-Policy, Allow).MIME types that should use immutable cache control.Constructor Summary
ConstructorsConstructorDescriptionEvery lookup table and every method here is static, so an instance holds no state of its own; the class is meant to be used through its static methods.Method Summary
All MethodsModifier and TypeMethodDescriptionstatic StringdetectMimeType(String url) Detects the MIME type based on a URL's file extension.static booleanisCustomWhitelist(String mimeType) Checks if a MIME type requires custom security headers.static booleanisImmutableCache(String mimeType) Checks if a MIME type should use immutable cache control headers.
Field Details
CUSTOM_WHITELIST_SET
IMMUTABLE_CACHE_WHITELIST_SET
Constructor Details
MimeTypeDetector
public MimeTypeDetector()Every lookup table and every method here is static, so an instance holds no state of its own; the class is meant to be used through its static methods.
Method Details
detectMimeType
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
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
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