public class SecurityHeaderBuilder extends Object
This class provides static methods for adding security-related HTTP headers to server responses. It handles:
Some headers are only added based on the MIME type of the response content. For example, Referrer-Policy and Allow headers are only added for HTML content. Cache-Control policies vary based on whether the content is static (immutable) or dynamic.
| Constructor and Description |
|---|
SecurityHeaderBuilder() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addSecurityHeaders(Map<String,List<String>> headers,
StringBuilder command,
String mimeType)
Adds all appropriate security headers to a response.
|
static void |
filterCacheControlHeaders(Map<String,List<String>> headers)
Filters Cache-Control headers to remove problematic values.
|
static void |
filterSetCookieHeaders(Map<String,List<String>> headers)
Filters Set-Cookie headers to remove unwanted cookies.
|
public static void addSecurityHeaders(Map<String,List<String>> headers, StringBuilder command, String mimeType)
This method adds security headers based on the MIME type of the response. Headers are only added if they are not already present in the response.
The following headers may be added:
headers - the HTTP response headers map to modifycommand - the HTTP request command (used for logging/debugging)mimeType - the MIME type of the response content; may be nullpublic static void filterCacheControlHeaders(Map<String,List<String>> headers)
This method removes "none" and "post-check" values from Cache-Control headers, as these can cause issues with I2P HTTP proxying.
headers - the HTTP response headers mappublic static void filterSetCookieHeaders(Map<String,List<String>> headers)
This method removes Set-Cookie headers containing specific strings (STYXKEY, visited=yes) that are known to be irrelevant or unwanted for I2P HTTP proxying.
headers - the HTTP response headers map