HttpHeaderValidationUtil Class — netty Architecture
Architecture documentation for the HttpHeaderValidationUtil class in HttpHeaderValidationUtil.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f369fc32_9e23_f7f4_8a18_b9a88f492d8b["HttpHeaderValidationUtil"] 9df1b5b5_bed8_8c69_11cd_8ec4fb66f5db["HttpHeaderValidationUtil.java"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|defined in| 9df1b5b5_bed8_8c69_11cd_8ec4fb66f5db 158231ff_44b0_396c_3cc8_84fc3a490200["HttpHeaderValidationUtil()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| 158231ff_44b0_396c_3cc8_84fc3a490200 8c581cc7_438d_997a_0367_2152cac71756["isConnectionHeader()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| 8c581cc7_438d_997a_0367_2152cac71756 1309e164_8bb9_c08d_54a8_8c8f580e8d01["isTeNotTrailers()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| 1309e164_8bb9_c08d_54a8_8c8f580e8d01 dd19c814_50c0_5afa_cb7c_3118cbf1a000["validateValidHeaderValue()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| dd19c814_50c0_5afa_cb7c_3118cbf1a000 a1048fa8_e69c_cc4e_36cb_ac59dd6fea9f["verifyValidHeaderValueAsciiString()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| a1048fa8_e69c_cc4e_36cb_ac59dd6fea9f aaedd47c_0623_411b_2832_bef342166d23["verifyValidHeaderValueCharSequence()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| aaedd47c_0623_411b_2832_bef342166d23 7f185b6c_fa74_b73c_1de9_b1b7b24d92cd["validateToken()"] f369fc32_9e23_f7f4_8a18_b9a88f492d8b -->|method| 7f185b6c_fa74_b73c_1de9_b1b7b24d92cd
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValidationUtil.java lines 25–181
public final class HttpHeaderValidationUtil {
private HttpHeaderValidationUtil() {
}
/**
* Check if a header name is "connection related".
* <p>
* The <a href="https://datatracker.ietf.org/doc/html/rfc9110#section-7.6.1">RFC9110</a> only specify an incomplete
* list of the following headers:
*
* <ul>
* <li><tt>Connection</tt></li>
* <li><tt>Proxy-Connection</tt></li>
* <li><tt>Keep-Alive</tt></li>
* <li><tt>TE</tt></li>
* <li><tt>Transfer-Encoding</tt></li>
* <li><tt>Upgrade</tt></li>
* </ul>
*
* @param name the name of the header to check. The check is case-insensitive.
* @param ignoreTeHeader {@code true} if the <tt>TE</tt> header should be ignored by this check.
* This is relevant for HTTP/2 header validation, where the <tt>TE</tt> header has special rules.
* @return {@code true} if the given header name is one of the specified connection-related headers.
*/
@SuppressWarnings("deprecation") // We need to check for deprecated headers as well.
public static boolean isConnectionHeader(CharSequence name, boolean ignoreTeHeader) {
// These are the known standard and non-standard connection related headers:
// - upgrade (7 chars)
// - connection (10 chars)
// - keep-alive (10 chars)
// - proxy-connection (16 chars)
// - transfer-encoding (17 chars)
//
// See https://datatracker.ietf.org/doc/html/rfc9113#section-8.2.2
// and https://datatracker.ietf.org/doc/html/rfc9110#section-7.6.1
// for the list of connection related headers.
//
// We scan for these based on the length, then double-check any matching name.
int len = name.length();
switch (len) {
case 2: return ignoreTeHeader? false : contentEqualsIgnoreCase(name, HttpHeaderNames.TE);
case 7: return contentEqualsIgnoreCase(name, HttpHeaderNames.UPGRADE);
case 10: return contentEqualsIgnoreCase(name, HttpHeaderNames.CONNECTION) ||
contentEqualsIgnoreCase(name, HttpHeaderNames.KEEP_ALIVE);
case 16: return contentEqualsIgnoreCase(name, HttpHeaderNames.PROXY_CONNECTION);
case 17: return contentEqualsIgnoreCase(name, HttpHeaderNames.TRANSFER_ENCODING);
default:
return false;
}
}
/**
* If the given header is {@link HttpHeaderNames#TE} and the given header value is <em>not</em>
* {@link HttpHeaderValues#TRAILERS}, then return {@code true}. Otherwie, {@code false}.
* <p>
* The string comparisons are case-insensitive.
* <p>
* This check is important for HTTP/2 header validation.
*
* @param name the header name to check if it is <tt>TE</tt> or not.
* @param value the header value to check if it is something other than <tt>TRAILERS</tt>.
* @return {@code true} only if the header name is <tt>TE</tt>, and the header value is <em>not</em>
* <tt>TRAILERS</tt>. Otherwise, {@code false}.
*/
public static boolean isTeNotTrailers(CharSequence name, CharSequence value) {
if (name.length() == 2) {
return contentEqualsIgnoreCase(name, HttpHeaderNames.TE) &&
!contentEqualsIgnoreCase(value, HttpHeaderValues.TRAILERS);
}
return false;
}
/**
* Validate the given HTTP header value by searching for any illegal characters.
*
* @param value the HTTP header value to validate.
* @return the index of the first illegal character found, or {@code -1} if there are none and the header value is
* valid.
*/
public static int validateValidHeaderValue(CharSequence value) {
int length = value.length();
Source
Frequently Asked Questions
What is the HttpHeaderValidationUtil class?
HttpHeaderValidationUtil is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValidationUtil.java.
Where is HttpHeaderValidationUtil defined?
HttpHeaderValidationUtil is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValidationUtil.java at line 25.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free