Class HttpParser
java.lang.Object
org.apache.tomcat.util.http.parser.HttpParser
HTTP header value parser implementation. Parsing HTTP headers as per RFC2616 is not always as simple as it first
appears. For headers that only use tokens the simple approach will normally be sufficient. However, for the other
headers, while simple code meets 99.9% of cases, there are often some edge cases that make things far more
complicated. The purpose of this parser is to let the parser worry about the edge cases. It provides tolerant (where
safe to do so) parsing of HTTP header values assuming that wrapped header lines have already been unwrapped. (The
Tomcat header processing code does the unwrapping.)
-
Constructor Summary
ConstructorsConstructorDescriptionHttpParser(String relaxedPathChars, String relaxedQueryChars) Creates a new HTTP parser with optional relaxed character sets for path and query. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisAbsolutePath(int c) Checks if the given character is valid for an absolute path as per RFC 3986.booleanisAbsolutePathRelaxed(int c) Checks if the given character is valid for a relaxed absolute path.static booleanisAlpha(int c) Checks if the given character is an alphabetic character.static booleanisControl(int c) Checks if the given character is a control character.static booleanisFieldContent(int c) Checks if the given character is valid field-content as per RFC 7230.static booleanisFieldVChar(int c) Checks if the given character is a valid field-vchar as per RFC 7230.static booleanisHex(int c) Checks if the given character is a valid hexadecimal digit.static booleanisHttpProtocol(int c) Checks if the given character is valid for an HTTP protocol version string.static booleanisNotRequestTarget(int c) Checks if the given character is not valid for a request target.booleanisNotRequestTargetRelaxed(int c) Checks if the given character is not valid for a relaxed request target.static booleanisNumeric(int c) Checks if the given character is a numeric digit.static booleanisQuery(int c) Checks if the given character is valid for a query string as per RFC 3986.booleanisQueryRelaxed(int c) Checks if the given character is valid for a relaxed query string.static booleanisScheme(int c) Checks if the given character is valid for a URI scheme as per RFC 3986.static booleanIs the provided String a scheme as per RFC 3986?static booleanisToken(int c) Checks if the given character is a valid HTTP token character as per RFC 7230.static booleanIs the provided String a token as per RFC 7230?static booleanisUserInfo(int c) Checks if the given character is valid for a URI userinfo component as per RFC 3986.static booleanisWhiteSpace(int c) Checks if the given character is whitespace (tab or space).static StringRemoves surrounding quotes from a string, handling escaped characters.
-
Constructor Details
-
HttpParser
Creates a new HTTP parser with optional relaxed character sets for path and query.- Parameters:
relaxedPathChars- Additional characters to allow in the path, ornullrelaxedQueryChars- Additional characters to allow in the query, ornull
-
-
Method Details
-
isNotRequestTargetRelaxed
public boolean isNotRequestTargetRelaxed(int c) Checks if the given character is not valid for a relaxed request target.- Parameters:
c- the character to check- Returns:
trueif the character is not valid for a request target
-
isAbsolutePathRelaxed
public boolean isAbsolutePathRelaxed(int c) Checks if the given character is valid for a relaxed absolute path.- Parameters:
c- the character to check- Returns:
trueif the character is valid for an absolute path
-
isQueryRelaxed
public boolean isQueryRelaxed(int c) Checks if the given character is valid for a relaxed query string.- Parameters:
c- the character to check- Returns:
trueif the character is valid for a query string
-
unquote
-
isToken
public static boolean isToken(int c) Checks if the given character is a valid HTTP token character as per RFC 7230.- Parameters:
c- the character to check- Returns:
trueif the character is a valid token character
-
isToken
Is the provided String a token as per RFC 7230?
Note: token = 1 * tchar (RFC 7230)
Since a token requires at least 1 tchar,nulland the empty string ("") are not considered to be valid tokens.- Parameters:
s- The string to test- Returns:
trueif the string is a valid token, otherwisefalse
-
isHex
public static boolean isHex(int c) Checks if the given character is a valid hexadecimal digit.- Parameters:
c- the character to check- Returns:
trueif the character is a valid hex digit
-
isNotRequestTarget
public static boolean isNotRequestTarget(int c) Checks if the given character is not valid for a request target.- Parameters:
c- the character to check- Returns:
trueif the character is not valid for a request target
-
isHttpProtocol
public static boolean isHttpProtocol(int c) Checks if the given character is valid for an HTTP protocol version string.- Parameters:
c- the character to check- Returns:
trueif the character is valid for an HTTP protocol version
-
isAlpha
public static boolean isAlpha(int c) Checks if the given character is an alphabetic character.- Parameters:
c- the character to check- Returns:
trueif the character is alphabetic
-
isNumeric
public static boolean isNumeric(int c) Checks if the given character is a numeric digit.- Parameters:
c- the character to check- Returns:
trueif the character is a numeric digit
-
isScheme
public static boolean isScheme(int c) Checks if the given character is valid for a URI scheme as per RFC 3986.- Parameters:
c- the character to check- Returns:
trueif the character is valid for a URI scheme
-
isScheme
Is the provided String a scheme as per RFC 3986?
Note: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Since a scheme requires at least 1 ALPHA,nulland the empty string ("") are not considered to be valid tokens.- Parameters:
s- The string to test- Returns:
trueif the string is a valid scheme, otherwisefalse
-
isUserInfo
public static boolean isUserInfo(int c) Checks if the given character is valid for a URI userinfo component as per RFC 3986.- Parameters:
c- the character to check- Returns:
trueif the character is valid for userinfo
-
isWhiteSpace
public static boolean isWhiteSpace(int c) Checks if the given character is whitespace (tab or space).- Parameters:
c- the character to check- Returns:
trueif the character is whitespace
-
isAbsolutePath
public static boolean isAbsolutePath(int c) Checks if the given character is valid for an absolute path as per RFC 3986.- Parameters:
c- the character to check- Returns:
trueif the character is valid for an absolute path
-
isQuery
public static boolean isQuery(int c) Checks if the given character is valid for a query string as per RFC 3986.- Parameters:
c- the character to check- Returns:
trueif the character is valid for a query string
-
isControl
public static boolean isControl(int c) Checks if the given character is a control character.- Parameters:
c- the character to check- Returns:
trueif the character is a control character
-
isFieldVChar
public static boolean isFieldVChar(int c) Checks if the given character is a valid field-vchar as per RFC 7230.- Parameters:
c- the character to check- Returns:
trueif the character is valid field-vchar
-
isFieldContent
public static boolean isFieldContent(int c) Checks if the given character is valid field-content as per RFC 7230.- Parameters:
c- the character to check- Returns:
trueif the character is valid field-content
-