Package org.omegazero.http.util
Class HTTPValidator
java.lang.Object
org.omegazero.http.util.HTTPValidator
Contains several methods for validating HTTP message components.
- Since:
- 1.2.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
bytesInRange
(byte[] bytes, int offset, int length, int min, int max) Checks that all bytes in the given byte array in the specified range starting at offset are within the given range of allowed values (min to max, inclusive).static int
Parses the given HTTP response status string.static boolean
Verifies the given HTTP URL authority string.static boolean
validMethod
(byte[] bytes, int offset, int length) Checks that the first length bytes in the given byte array, starting at offset, represent a valid HTTP request method string.static boolean
Verifies the given HTTP request method string.static boolean
Verifies the given HTTP URL path string.static boolean
Verifies the given HTTP response status string.static boolean
validString
(byte[] bytes, int offset, int length) Checks that the first length bytes in the given byte array, starting at offset, only consist of visible printable ASCII characters (range 33 - 126 inclusive).static boolean
Checks that the given string is notnull
and only consists of visible printable ASCII characters (range 33 - 126 inclusive).
-
Method Details
-
validMethod
Verifies the given HTTP request method string. This string is considered valid if it is notnull
and consists solely of 2-10 uppercase letters.- Parameters:
s
- The string to check- Returns:
true
if the given string is a valid HTTP request method string- See Also:
-
validMethod
public static boolean validMethod(byte[] bytes, int offset, int length) Checks that the first length bytes in the given byte array, starting at offset, represent a valid HTTP request method string.- Parameters:
bytes
- The byte arrayoffset
- The index to start atlength
- The number of bytes to check- Returns:
true
if the given bytes represent a valid HTTP request method string- See Also:
-
validAuthority
Verifies the given HTTP URL authority string. This string is considered valid if it is notnull
and only consists of printable ASCII characters.- Parameters:
s
- The string to check- Returns:
true
if the given string is a valid HTTP URL authority string- See Also:
-
validPath
Verifies the given HTTP URL path string. This string is considered valid if it is notnull
and either starts with a slash ('/'
) and only contains printable ASCII characters or is exactly equal to'*'
.- Parameters:
s
- The string to check- Returns:
true
if the given string is a valid HTTP URL path string- See Also:
-
validStatus
Verifies the given HTTP response status string. This string is considered valid if consists of exactly 3 digits ('0'
-'9'
).- Parameters:
s
- The string to check- Returns:
true
if the given string is a valid HTTP response status string- See Also:
-
parseStatus
Parses the given HTTP response status string.- Parameters:
s
- The string to parse- Returns:
- The status number that the given string represents, or
-1
if the string is not a valid status code - See Also:
-
validString
Checks that the given string is notnull
and only consists of visible printable ASCII characters (range 33 - 126 inclusive).- Parameters:
s
- The string to check- Returns:
true
if the given string is valid- See Also:
-
validString
public static boolean validString(byte[] bytes, int offset, int length) Checks that the first length bytes in the given byte array, starting at offset, only consist of visible printable ASCII characters (range 33 - 126 inclusive).- Parameters:
bytes
- The byte arrayoffset
- The index to start atlength
- The number of bytes to check- Returns:
true
if the given bytes are valid- See Also:
-
bytesInRange
public static boolean bytesInRange(byte[] bytes, int offset, int length, int min, int max) Checks that all bytes in the given byte array in the specified range starting at offset are within the given range of allowed values (min to max, inclusive).- Parameters:
bytes
- The byte arrayoffset
- The index to start atlength
- The number of bytes to checkmin
- The minimum allowed byte valuemax
- The maximum allowed byte value- Returns:
true
if the given bytes are within the allowed range
-