Class HTTPValidator

java.lang.Object
org.omegazero.http.util.HTTPValidator

public final class HTTPValidator extends Object
Contains several methods for validating HTTP message components.
Since:
1.2.1
  • Method Summary

    Modifier and Type
    Method
    Description
    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).
    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 not null and only consists of visible printable ASCII characters (range 33 - 126 inclusive).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • validMethod

      public static boolean validMethod(String s)
      Verifies the given HTTP request method string. This string is considered valid if it is not null 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 array
      offset - The index to start at
      length - The number of bytes to check
      Returns:
      true if the given bytes represent a valid HTTP request method string
      See Also:
    • validAuthority

      public static boolean validAuthority(String s)
      Verifies the given HTTP URL authority string. This string is considered valid if it is not null 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

      public static boolean validPath(String s)
      Verifies the given HTTP URL path string. This string is considered valid if it is not null 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

      public static boolean validStatus(String s)
      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

      public static int parseStatus(String s)
      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

      public static boolean validString(String s)
      Checks that the given string is not null 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 array
      offset - The index to start at
      length - 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 array
      offset - The index to start at
      length - The number of bytes to check
      min - The minimum allowed byte value
      max - The maximum allowed byte value
      Returns:
      true if the given bytes are within the allowed range