Represent a single header field for an HTTP connection. More...
Public Member Functions | |
BHttpHeader () | |
Default constructor. More... | |
BHttpHeader (const BHttpHeader ©) | |
Copy constructor. | |
BHttpHeader (const char *name, const char *value) | |
Construct a BHttpHeader from an unencoded key-value pair. More... | |
BHttpHeader (const char *string) | |
Construct a BHttpHeader from an already encoded string. More... | |
const char * | Header () const |
const char * | Name () const |
bool | NameIs (const char *name) const |
Compare this header name with the given one. More... | |
bool | SetHeader (const char *string) |
Parse the given string and configure this object. More... | |
void | SetName (const char *name) |
Sets the key for this header. More... | |
void | SetValue (const char *value) |
Sets the value for this header. More... | |
const char * | Value () const |
Represent a single header field for an HTTP connection.
HTTP headers are key-value pairs, where both the key and the value are strings. The main purpose of this class is storing the pair and encoding it to the HTTP protocol format, where some characters have to be escaped.
BHttpHeader::BHttpHeader | ( | ) |
Default constructor.
The header is initialized with empty key and value.
BHttpHeader::BHttpHeader | ( | const char * | string | ) |
Construct a BHttpHeader from an already encoded string.
The given string should be in the form "key:value" with all special characters properly escaped. There is no way to detect parsing errors when the given string is not properly formatted. Consider using SetHeader() instead, where this can be checked.
string | the http-encoded header to parse |
BHttpHeader::BHttpHeader | ( | const char * | name, |
const char * | value | ||
) |
Construct a BHttpHeader from an unencoded key-value pair.
name | the key |
value | the value |
const char * BHttpHeader::Header | ( | ) | const |
const char * BHttpHeader::Name | ( | ) | const |
bool BHttpHeader::NameIs | ( | const char * | name | ) | const |
Compare this header name with the given one.
Both names are trimmed from whitespace, and the comparison is not case sensitive (as per the HTTP specification).
bool BHttpHeader::SetHeader | ( | const char * | string | ) |
Parse the given string and configure this object.
Extracts and decode the name and value from the given string.
string | the header data to parse |
void BHttpHeader::SetName | ( | const char * | name | ) |
Sets the key for this header.
The key is trimmed (BString::Trim()) to remove any whitespace.
name | the new key |
void BHttpHeader::SetValue | ( | const char * | value | ) |
Sets the value for this header.
The value is trimmed (BString::Trim()) to remove any whitespace.
value | the new value |
const char * BHttpHeader::Value | ( | ) | const |