Class HTTPTools

java.lang.Object
io.fusionauth.http.util.HTTPTools

public final class HTTPTools extends Object
  • Constructor Details

    • HTTPTools

      public HTTPTools()
  • Method Details

    • initialize

      public static void initialize(LoggerFactory loggerFactory)
      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

      public static HTTPTools.HeaderValue parseHeaderValue(String value)
      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.