java.lang.Object
org.cybergarage.http.HTTPHeader

public class HTTPHeaderextends Object
Represents an HTTP header field with a name and value. This class provides methods to parse, manipulate, and extract HTTP headers from various data sources including strings, byte arrays, and readers.
  • Field Details

    • MAX_LENGTH

      private static int MAX_LENGTH
      Maximum length for HTTP header lines to prevent excessive memory usage. Headers longer than this limit will be truncated during parsing.
    • name

      private String name
      The header's field name.
    • value

      private String value
      The header's field value.
  • Constructor Details

    • HTTPHeader

      public HTTPHeader(String name, String value)
      Creates a new HTTPHeader with the specified name and value.
      Parameters:
      name - the header name
      value - the header value
    • HTTPHeader

      public HTTPHeader(String lineStr)
      Creates a new HTTPHeader by parsing a header line string. The line should be in the format "Name: Value".
      Parameters:
      lineStr - the header line to parse
  • Method Details

    • setName

      public void setName(String name)
      Sets the header name.
      Parameters:
      name - the header name to set
    • setValue

      public void setValue(String value)
      Sets the header value.
      Parameters:
      value - the header value to set
    • getName

      public String getName()
      Gets the header name.
      Returns:
      the header name
    • getValue

      public String getValue()
      Gets the header value.
      Returns:
      the header value
    • hasName

      public boolean hasName()
      Checks if this header has a valid name.
      Returns:
      true if the header has a non-null, non-empty name
    • getValue

      public static final String getValue(LineNumberReader reader, String name)
      Reads from a LineNumberReader to find the value of a header with the specified name. The search is case-insensitive.
      Parameters:
      reader - the LineNumberReader to read from
      name - the name of the header to find
      Returns:
      the header value, or empty string if not found
    • getValue

      public static final String getValue(String data, String name)
      Extracts the value of a header with the specified name from a string. The search is case-insensitive.
      Parameters:
      data - the string containing HTTP headers
      name - the name of the header to find
      Returns:
      the header value, or empty string if not found
    • getValue

      public static final String getValue(byte[] data, String name)
      Extracts the value of a header with the specified name from a byte array. The search is case-insensitive.
      Parameters:
      data - the byte array containing HTTP headers
      name - the name of the header to find
      Returns:
      the header value, or empty string if not found
    • getIntegerValue

      public static final int getIntegerValue(String data, String name)
      Extracts the integer value of a header with the specified name from a string.
      Parameters:
      data - the string containing HTTP headers
      name - the name of the header to find
      Returns:
      the header value as an integer, or 0 if not found or invalid
    • getIntegerValue

      public static final int getIntegerValue(byte[] data, String name)
      Extracts the integer value of a header with the specified name from a byte array.
      Parameters:
      data - the byte array containing HTTP headers
      name - the name of the header to find
      Returns:
      the header value as an integer, or 0 if not found or invalid