#include <HeaderBase.h> [code]
Inherits Protocols::Generics::DataBase.
Inherited by Protocols::Http::BodyEnd, Protocols::Http::RequestHeader, and Protocols::Http::ResponseHeader.
Inheritance diagram for Protocols::Http::HeaderBase:


This class is designed to store, parse and write HTTP header fields which can be found in message headers or chunk headers. Their syntax and symantics are described in RFC 2616.
You can parse a bunch of headers from a QString into a Header object using parse().
To get the header fields as raw bytes use the function
HeaderBase implements DataBase but has the special property that it is not an abstract class and thus can be instantiated. In fact Header uses a default constructed HeaderBase object as a Null object.
Definition at line 48 of file HeaderBase.h.
Public Member Functions | |
| auto_ptr< DataBase > | copy () const |
| Virtual copy constructor. | |
| QByteArray | toRawBytes () const |
| Returns the raw byte representation of the HTTP header. | |
| HeaderBase () | |
| Default constructor. | |
| virtual | ~HeaderBase () |
| Destructor. | |
| bool | operator== (const HeaderBase &) const |
| Equality operator. | |
| bool | operator!= (const HeaderBase &) const |
| Inequality operator. | |
| bool | parse (const QByteArray &rawBytes) |
| Parses the HTTP header fields encoded in the rawBytes. | |
| QList< QByteArray > | fields () const |
| Returns the names of all contained header fields (all in lower case). | |
| bool | hasField (const QByteArray &key) const |
| Checks whether or not a field with name fieldName exists in this header. | |
| QByteArray | fieldValue (const QByteArray &fieldName) const |
| Returns the field value for the header field with name fieldName. | |
| QList< QByteArray > | fieldValues (const QByteArray &fieldName) const |
| Returns the list of field values for the field with name fieldName. | |
| void | setFieldValue (const QByteArray &fieldName, const QByteArray &fieldValue) |
| Sets the value of the field with name fieldName to value. | |
| void | addFieldValue (const QByteArray &fieldName, const QByteArray &fieldValue) |
| Adds a new field value fieldValue to the field with name fieldName. | |
| void | addFieldValues (const QByteArray &fieldName, const QList< QByteArray > &fieldValues) |
| Adds the list of field values to the field with name fieldName. | |
| void | removeField (const QByteArray &fieldName) |
| Removes the field with name fieldName from the HTTP header. | |
Protected Member Functions | |
| HeaderBase (Data *d) | |
| Protected constructor initializing the shared private data. | |
| virtual bool | parseStartLine (const QByteArray &startLine) |
| Called to parse the start line of a HTTP header. | |
| virtual QByteArray | rawStartLine () const |
| Raw representation of the header's start line. | |
Protected Attributes | |
| SharedDataPointer | d_ptr |
| Pointer to the implicitly shared private data. | |
Private Member Functions | |
| Q_DECLARE_SHARED_DATA (Data) | |
| bool | doParse (const QByteArray &rawBytes) |
| Helper that does the actual parsing of rawBytes. | |
| bool | parseAllLines (const QList< QByteArray > &lines) |
| Helper to parse the header lines in lines. | |
| bool | parseHeaderLine (const QByteArray &line) |
| Tries to parse the raw header in line. | |
| QByteArray | rawHeaderLine (const QByteArray &name) const |
| Helper returning the raw bytes header line representation for fieldName. | |
Static Private Member Functions | |
| static QList< QByteArray > | splitStringIntoLines (const QByteArray &str) |
| Helper to split str into a list of header lines. | |
Classes | |
| class | Data |
|
|
Default constructor.
Definition at line 28 of file HeaderBase.cpp. |
|
|
Destructor.
Definition at line 40 of file HeaderBase.cpp. |
|
|
Protected constructor initializing the shared private data.
Definition at line 34 of file HeaderBase.cpp. |
|
||||||||||||
|
Adds a new field value fieldValue to the field with name fieldName. If the field does not exist, it will be created.
Definition at line 200 of file HeaderBase.cpp. |
|
||||||||||||
|
Adds the list of field values to the field with name fieldName. If the field does not exist, it will be created.
Definition at line 221 of file HeaderBase.cpp. |
|
|
Virtual copy constructor.
Implements Protocols::Generics::DataBase. Reimplemented in Protocols::Http::BodyEnd, Protocols::Http::RequestHeader, and Protocols::Http::ResponseHeader. Definition at line 57 of file HeaderBase.cpp. |
|
|
Helper that does the actual parsing of rawBytes.
Definition at line 300 of file HeaderBase.cpp. |
|
|
Returns the names of all contained header fields (all in lower case).
Definition at line 139 of file HeaderBase.cpp. |
|
|
Returns the field value for the header field with name fieldName. If no header field fieldName exists, an empty string is returned. If multiple field values are available, they are returned as comma-separated list in a single string.
Definition at line 120 of file HeaderBase.cpp. |
|
|
Returns the list of field values for the field with name fieldName. If no field with name fieldName exists, and empty list is returned.
Definition at line 166 of file HeaderBase.cpp. |
|
|
Checks whether or not a field with name fieldName exists in this header.
Definition at line 153 of file HeaderBase.cpp. |
|
|
Inequality operator.
Definition at line 51 of file HeaderBase.cpp. |
|
|
Equality operator.
Definition at line 45 of file HeaderBase.cpp. |
|
|
Parses the HTTP header fields encoded in the rawBytes.
Definition at line 73 of file HeaderBase.cpp. |
|
|
Helper to parse the header lines in lines. Allows for the first line to be parsed differently by calling the hook parseStartLine(). If it returns false, the line is parsed as a normal header line. Definition at line 330 of file HeaderBase.cpp. |
|
|
Tries to parse the raw header in line.
Definition at line 360 of file HeaderBase.cpp. |
|
|
Called to parse the start line of a HTTP header. HeaderBase-derived classes can reimplement this function to parse their own specific start lines.
Reimplemented in Protocols::Http::RequestHeader, and Protocols::Http::ResponseHeader. Definition at line 350 of file HeaderBase.cpp. |
|
|
|
|
|
Helper returning the raw bytes header line representation for fieldName.
Definition at line 273 of file HeaderBase.cpp. |
|
|
Raw representation of the header's start line. HeaderBase derived classes can reimplement this function. Reimplemented in Protocols::Http::RequestHeader, and Protocols::Http::ResponseHeader. Definition at line 267 of file HeaderBase.cpp. |
|
|
Removes the field with name fieldName from the HTTP header.
Definition at line 232 of file HeaderBase.cpp. |
|
||||||||||||
|
Sets the value of the field with name fieldName to value. If no field with fieldName exists, a new field with the given fieldName and fieldValue is created. If a field with the fieldName already exists, its values are discarded and replaced with the given fieldValue. If the fieldValue is a comma-separated string, it is split in sub values and they are all associated with the header field.
Definition at line 187 of file HeaderBase.cpp. |
|
|
Helper to split str into a list of header lines. Uses <CR><LF> or <LF> as line separators. Ignores empty lines. Definition at line 315 of file HeaderBase.cpp. |
|
|
Returns the raw byte representation of the HTTP header. Each header field is finished by a "\r\n". Long header fields (more than 80 chars) are broken on multiple lines. The BNF from RFC-2616: generic-message = start-line *(message-header CRLF) CRLF [ message-body ] start-line = Request-Line | Status-Line
Implements Protocols::Generics::DataBase. Definition at line 101 of file HeaderBase.cpp. |
|
|
Pointer to the implicitly shared private data.
Definition at line 95 of file HeaderBase.h. |