java.lang.Object
org.cybergarage.http.HTTPHeader
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 Summary
Constructor Summary
ConstructorsConstructorDescriptionHTTPHeader(String lineStr) Creates a new HTTPHeader by parsing a header line string.HTTPHeader(String name, String value) Creates a new HTTPHeader with the specified name and value.Method Summary
Modifier and TypeMethodDescriptionstatic final intgetIntegerValue(byte[] data, String name) Extracts the integer value of a header with the specified name from a byte array.static final intgetIntegerValue(String data, String name) Extracts the integer value of a header with the specified name from a string.getName()Gets the header name.getValue()Gets the header value.static final StringExtracts the value of a header with the specified name from a byte array.static final StringgetValue(LineNumberReader reader, String name) Reads from a LineNumberReader to find the value of a header with the specified name.static final StringExtracts the value of a header with the specified name from a string.booleanhasName()Checks if this header has a valid name.voidSets the header name.voidSets the header value.
Field Details
MAX_LENGTH
private static int MAX_LENGTHMaximum length for HTTP header lines to prevent excessive memory usage. Headers longer than this limit will be truncated during parsing.name
The header's field name.value
The header's field value.
Constructor Details
HTTPHeader
HTTPHeader
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
setValue
getName
getValue
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
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 fromname- the name of the header to find- Returns:
- the header value, or empty string if not found
getValue
Extracts the value of a header with the specified name from a string. The search is case-insensitive.- Parameters:
data- the string containing HTTP headersname- the name of the header to find- Returns:
- the header value, or empty string if not found
getValue
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 headersname- the name of the header to find- Returns:
- the header value, or empty string if not found
getIntegerValue
getIntegerValue
Extracts the integer value of a header with the specified name from a byte array.- Parameters:
data- the byte array containing HTTP headersname- the name of the header to find- Returns:
- the header value as an integer, or 0 if not found or invalid