Package io.fusionauth.http.util
Class HTTPTools
java.lang.Object
io.fusionauth.http.util.HTTPTools
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA record that stores a parameterized header value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidinitialize(LoggerFactory loggerFactory) Statically sets up the logger, mostly for trace logging.static booleanisDigitCharacter(byte ch) Determines if the given character (byte) is a digit (i.e.static booleanisHexadecimalCharacter(byte ch) Determines if the given character (byte) is an allowed hexadecimal character (i.e.static booleanisTokenCharacter(byte ch) Determines if the given character (byte) is an allowed HTTP token character (header field names, methods, etc).static booleanisURICharacter(byte ch) Naively determines if the given character (byte) is an allowed URI character.static booleanisValueCharacter(byte ch) static voidparseEncodedData(byte[] data, int start, int length, Map<String, List<String>> result) Parses URL encoded data either from a URL parameter list in the query string or the form body.static HTTPTools.HeaderValueparseHeaderValue(String value) Parses an HTTP header value that is a standard semicolon separated list of values.static byte[]parseRequestPreamble(InputStream inputStream, HTTPRequest request, byte[] requestBuffer, Instrumenter instrumenter, Runnable readObserver) Parses the request preamble directly from the given InputStream.static voidwriteResponsePreamble(HTTPResponse response, OutputStream outputStream) Writes the HTTP response head section (status line, headers, etc).
-
Constructor Details
-
HTTPTools
public HTTPTools()
-
-
Method Details
-
initialize
Statically sets up the logger, mostly for trace logging.- Parameters:
loggerFactory- The logger factory.
-
isDigitCharacter
public static boolean isDigitCharacter(byte ch) Determines if the given character (byte) is a digit (i.e. 0-9)- Parameters:
ch- The character as a byte since HTTP is ASCII.- Returns:
- True if the character is a digit.
-
isHexadecimalCharacter
public static boolean isHexadecimalCharacter(byte ch) Determines if the given character (byte) is an allowed hexadecimal character (i.e. 0-9a-zA-Z)- Parameters:
ch- The character as a byte since HTTP is ASCII.- Returns:
- True if the character is a hexadecimal character.
-
isTokenCharacter
public static boolean isTokenCharacter(byte ch) Determines if the given character (byte) is an allowed HTTP token character (header field names, methods, etc).Covered by https://www.rfc-editor.org/rfc/rfc9110.html#name-fields
- Parameters:
ch- The character as a byte since HTTP is ASCII.- Returns:
- True if the character is a token character.
-
isURICharacter
public static boolean isURICharacter(byte ch) Naively determines if the given character (byte) is an allowed URI character.- Parameters:
ch- The character as a byte since URIs are ASCII.- Returns:
- True if the character is a URI character.
-
isValueCharacter
public static boolean isValueCharacter(byte ch) -
parseEncodedData
public static void parseEncodedData(byte[] data, int start, int length, Map<String, List<String>> result) Parses URL encoded data either from a URL parameter list in the query string or the form body.- Parameters:
data- The data as a character array.start- The start index to start parsing from.length- The length to parse.result- The result Map to put the value into.
-
parseHeaderValue
Parses an HTTP header value that is a standard semicolon separated list of values.- Parameters:
value- The header value.- Returns:
- The HeaderValue record.
-
parseRequestPreamble
public static byte[] parseRequestPreamble(InputStream inputStream, HTTPRequest request, byte[] requestBuffer, Instrumenter instrumenter, Runnable readObserver) throws IOException Parses the request preamble directly from the given InputStream.- Parameters:
inputStream- The input stream to read the preamble from.request- The HTTP request to populate.requestBuffer- A buffer used for reading to help reduce memory thrashing.instrumenter- The Instrumenter that is informed of bytes read.readObserver- An observer that is called once one byte has been read.- Returns:
- Any leftover body bytes from the last read from the InputStream.
- Throws:
IOException- If the read fails.
-
writeResponsePreamble
public static void writeResponsePreamble(HTTPResponse response, OutputStream outputStream) throws IOException Writes the HTTP response head section (status line, headers, etc).- Parameters:
response- The response.outputStream- The output stream to write the preamble to.- Throws:
IOException- If the stream threw an exception.
-