#include <Pt/Http/Message.h>
HTTP message header. More...
Inherits NonCopyable.
Classes | |
| class | Field |
| Field of a HTTP header. More... | |
| class | ConstIterator |
| HTTP header field iterator. More... | |
Public Member Functions | |
| MessageHeader () | |
| Default constructor. | |
| ~MessageHeader () | |
| Destructor. | |
| void | clear () |
| Clears all content. | |
| void | set (const char *key, const char *value) |
| Sets a header field. | |
| void | add (const char *key, const char *value) |
| Adds a header field. | |
| void | remove (const char *key) |
| Removes a header field. | |
| const char * | get (const char *key) const |
| Returns a field value. | |
| bool | has (const char *key) const |
| Returns true if the field is present. | |
| bool | isSet (const char *key, const char *value) const |
| Returns true if the field is set to the value. | |
| ConstIterator | begin () const |
| Returns the begin of the header fields. | |
| ConstIterator | end () const |
| Returns the end of the header fields. | |
| unsigned | versionMajor () const |
| Returns the major HTTP version number. | |
| unsigned | versionMinor () const |
| Returns the minor HTTP version number. | |
| void | setVersion (unsigned major, unsigned minor) |
| Sets the HTTP version number. | |
| bool | isChunked () const |
| Returns true if chunked encoding is set. | |
| std::size_t | contentLength () const |
| Returns the content length. | |
| bool | isKeepAlive () const |
| Returns true if HTTP keep-alive is set. | |
| void | setKeepAlive () |
| Sets the HTTP keep-alive header. | |
| bool | isUpgrade () const |
| Returns true if the Upgrade header is set. | |
| void | setUpgrade () |
| Sets the Upgrade header. | |
Static Public Member Functions | |
| static char * | htdateCurrent (char *buffer) |
| Writes a current HTTP date into buffer. | |
MessageHeader is the field list and HTTP version of a message. It is the header half of Message, and through that of Request and Reply. Callers do not usually construct a header on its own; they use header() on the message the client or responder already holds.
Fields are names and values. set() replaces the value for a name, add() appends another value for the same name, and remove() deletes it. get() returns the value or a null pointer, has() reports presence, and isSet() tests that a name has a particular value. begin() and end() walk the fields as Field values, each with a name and a value pointer into the header's buffer.
Keep-alive, chunked transfer coding, content length and Upgrade are not a second header model: they are derived from those fields. isKeepAlive(), isChunked(), contentLength() and isUpgrade() read them, while setKeepAlive() and setUpgrade() write the corresponding fields. HTTP version is versionMajor() and versionMinor(), set together with setVersion().
The header has a fixed size, so the caller must not rely on filling it beyond that limit. clear() empties the fields so the same header can be used for another message.
|
static |
buffer must have at least 30 bytes.