Public Member Functions | List of all members
BHttpHeader Class Reference

Represent a single header field for an HTTP connection. More...

Public Member Functions

 BHttpHeader ()
 Default constructor. More...
 
 BHttpHeader (const char *string)
 Construct a BHttpHeader from an already encoded string. More...
 
 BHttpHeader (const char *name, const char *value)
 Construct a BHttpHeader from an unencoded key-value pair. More...
 
 BHttpHeader (const BHttpHeader &copy)
 Copy constructor.
 
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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ BHttpHeader() [1/3]

BHttpHeader::BHttpHeader ( )

Default constructor.

The header is initialized with empty key and value.

◆ BHttpHeader() [2/3]

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.

Parameters
stringthe http-encoded header to parse

◆ BHttpHeader() [3/3]

BHttpHeader::BHttpHeader ( const char *  name,
const char *  value 
)

Construct a BHttpHeader from an unencoded key-value pair.

Parameters
namethe key
valuethe value

Member Function Documentation

◆ Header()

const char * BHttpHeader::Header ( ) const
Returns
the encoded header

◆ Name()

const char * BHttpHeader::Name ( ) const
Returns
the key for this header

◆ NameIs()

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).

◆ SetHeader()

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.

Parameters
stringthe header data to parse
Returns
wether parsing succeeded

◆ SetName()

void BHttpHeader::SetName ( const char *  name)

Sets the key for this header.

The key is trimmed (BString::Trim()) to remove any whitespace.

Parameters
namethe new key

◆ SetValue()

void BHttpHeader::SetValue ( const char *  value)

Sets the value for this header.

The value is trimmed (BString::Trim()) to remove any whitespace.

Parameters
valuethe new value

◆ Value()

const char * BHttpHeader::Value ( ) const
Returns
the value for this header