Qt 4.8
|
The QHttpHeader class contains header information for HTTP. More...
#include <qhttp.h>
Public Functions | |
void | addValue (const QString &key, const QString &value) |
Adds a new entry with the key and value. More... | |
QStringList | allValues (const QString &key) const |
Returns all the entries with the given key. More... | |
uint | contentLength () const |
Returns the value of the special HTTP header field content-length . More... | |
QString | contentType () const |
Returns the value of the special HTTP header field content-type . More... | |
bool | hasContentLength () const |
Returns true if the header has an entry for the special HTTP header field content-length ; otherwise returns false. More... | |
bool | hasContentType () const |
Returns true if the header has an entry for the special HTTP header field content-type ; otherwise returns false. More... | |
bool | hasKey (const QString &key) const |
Returns true if the HTTP header has an entry with the given key; otherwise returns false. More... | |
bool | isValid () const |
Returns true if the HTTP header is valid; otherwise returns false. More... | |
QStringList | keys () const |
Returns a list of the keys in the HTTP header. More... | |
virtual int | majorVersion () const =0 |
Returns the major protocol-version of the HTTP header. More... | |
virtual int | minorVersion () const =0 |
Returns the minor protocol-version of the HTTP header. More... | |
QHttpHeader & | operator= (const QHttpHeader &h) |
Assigns h and returns a reference to this http header. More... | |
QHttpHeader () | |
Constructs an empty HTTP header. More... | |
QHttpHeader (const QHttpHeader &header) | |
Constructs a copy of header. More... | |
QHttpHeader (const QString &str) | |
Constructs a HTTP header for str. More... | |
void | removeAllValues (const QString &key) |
Removes all the entries with the key key from the HTTP header. More... | |
void | removeValue (const QString &key) |
Removes the entry with the key key from the HTTP header. More... | |
void | setContentLength (int len) |
Sets the value of the special HTTP header field content-length to len. More... | |
void | setContentType (const QString &type) |
Sets the value of the special HTTP header field content-type to type. More... | |
void | setValue (const QString &key, const QString &value) |
Sets the value of the entry with the key to value. More... | |
void | setValues (const QList< QPair< QString, QString > > &values) |
Sets the header entries to be the list of key value pairs in values. More... | |
virtual QString | toString () const |
Returns a string representation of the HTTP header. More... | |
QString | value (const QString &key) const |
Returns the first value for the entry with the given key. More... | |
QList< QPair< QString, QString > > | values () const |
Returns all the entries in the header. More... | |
virtual | ~QHttpHeader () |
Destructor. More... | |
Protected Functions | |
bool | parse (const QString &str) |
Parses the HTTP header string str for header fields and adds the keys/values it finds. More... | |
virtual bool | parseLine (const QString &line, int number) |
Parses the single HTTP header line line which has the format key, colon, space, value, and adds key/value to the headers. More... | |
QHttpHeader (QHttpHeaderPrivate &dd, const QString &str=QString()) | |
QHttpHeader (QHttpHeaderPrivate &dd, const QHttpHeader &header) | |
void | setValid (bool) |
Protected Variables | |
QScopedPointer< QHttpHeaderPrivate > | d_ptr |
The QHttpHeader class contains header information for HTTP.
In most cases you should use the more specialized derivatives of this class, QHttpResponseHeader and QHttpRequestHeader, rather than directly using QHttpHeader.
QHttpHeader provides the HTTP header fields. A HTTP header field consists of a name followed by a colon, a single space, and the field value. (See RFC 1945.) Field names are case-insensitive. A typical header field looks like this:
In the API the header field name is called the "key" and the content is called the "value". You can get and set a header field's value by using its key with value() and setValue(), e.g.
Some fields are so common that getters and setters are provided for them as a convenient alternative to using value() and setValue() , e.g. contentLength() and contentType(), setContentLength() and setContentType().
Each header key has a single value associated with it. If you set the value for a key which already exists the previous value will be discarded.
QHttpHeader::QHttpHeader | ( | ) |
Constructs an empty HTTP header.
Definition at line 578 of file qhttp.cpp.
QHttpHeader::QHttpHeader | ( | const QHttpHeader & | header | ) |
Constructs a copy of header.
Definition at line 589 of file qhttp.cpp.
QHttpHeader::QHttpHeader | ( | const QString & | str | ) |
Constructs a HTTP header for str.
This constructor parses the string str for header fields and adds this information. The str should consist of one or more "\r\n" delimited lines; each of these lines should have the format key, colon, space, value.
Definition at line 606 of file qhttp.cpp.
|
virtual |
|
protected |
Definition at line 617 of file qhttp.cpp.
|
protected |
Definition at line 629 of file qhttp.cpp.
Adds a new entry with the key and value.
Definition at line 843 of file qhttp.cpp.
Referenced by parseLine(), and setValue().
QStringList QHttpHeader::allValues | ( | const QString & | key | ) | const |
Returns all the entries with the given key.
If no entry has this key, an empty string list is returned.
Definition at line 749 of file qhttp.cpp.
uint QHttpHeader::contentLength | ( | ) | const |
Returns the value of the special HTTP header field content-length
.
Definition at line 956 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotClosed(), and QHttpPrivate::_q_slotReadyRead().
QString QHttpHeader::contentType | ( | ) | const |
Returns the value of the special HTTP header field content-type
.
Definition at line 988 of file qhttp.cpp.
bool QHttpHeader::hasContentLength | ( | ) | const |
Returns true if the header has an entry for the special HTTP header field content-length
; otherwise returns false.
Definition at line 945 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotReadyRead().
bool QHttpHeader::hasContentType | ( | ) | const |
Returns true if the header has an entry for the special HTTP header field content-type
; otherwise returns false.
Definition at line 978 of file qhttp.cpp.
bool QHttpHeader::hasKey | ( | const QString & | key | ) | const |
Returns true if the HTTP header has an entry with the given key; otherwise returns false.
Definition at line 792 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotClosed(), QHttpPrivate::_q_slotReadyRead(), hasContentLength(), and hasContentType().
bool QHttpHeader::isValid | ( | ) | const |
Returns true if the HTTP header is valid; otherwise returns false.
A QHttpHeader is invalid if it was created by parsing a malformed string.
Definition at line 660 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotReadyRead(), and toString().
QStringList QHttpHeader::keys | ( | ) | const |
Returns a list of the keys in the HTTP header.
Definition at line 768 of file qhttp.cpp.
|
pure virtual |
Returns the major protocol-version of the HTTP header.
Implemented in QHttpRequestHeader, and QHttpResponseHeader.
|
pure virtual |
Returns the minor protocol-version of the HTTP header.
Implemented in QHttpRequestHeader, and QHttpResponseHeader.
QHttpHeader & QHttpHeader::operator= | ( | const QHttpHeader & | h | ) |
Assigns h and returns a reference to this http header.
Definition at line 647 of file qhttp.cpp.
Referenced by QHttpResponseHeader::operator=(), and QHttpRequestHeader::operator=().
|
protected |
Parses the HTTP header string str for header fields and adds the keys/values it finds.
Returns true if str was successfully parsed; otherwise returns false.
Definition at line 678 of file qhttp.cpp.
Referenced by QHttpHeader(), QHttpRequestHeader::QHttpRequestHeader(), and QHttpResponseHeader::QHttpResponseHeader().
|
protectedvirtual |
Parses the single HTTP header line line which has the format key, colon, space, value, and adds key/value to the headers.
Reimplemented in QHttpRequestHeader, and QHttpResponseHeader.
Definition at line 905 of file qhttp.cpp.
Referenced by parse(), QHttpResponseHeader::parseLine(), and QHttpRequestHeader::parseLine().
void QHttpHeader::removeAllValues | ( | const QString & | key | ) |
Removes all the entries with the key key from the HTTP header.
Definition at line 880 of file qhttp.cpp.
void QHttpHeader::removeValue | ( | const QString & | key | ) |
Removes the entry with the key key from the HTTP header.
Definition at line 863 of file qhttp.cpp.
void QHttpHeader::setContentLength | ( | int | len | ) |
Sets the value of the special HTTP header field content-length
to len.
Definition at line 967 of file qhttp.cpp.
void QHttpHeader::setContentType | ( | const QString & | type | ) |
Sets the value of the special HTTP header field content-type
to type.
Definition at line 1007 of file qhttp.cpp.
|
protected |
Definition at line 720 of file qhttp.cpp.
Referenced by QHttpRequestHeader::QHttpRequestHeader(), QHttpResponseHeader::QHttpResponseHeader(), QHttpRequestHeader::setRequest(), and QHttpResponseHeader::setStatusLine().
Sets the value of the entry with the key to value.
If no entry with key exists, a new entry with the given key and value is created. If an entry with the key already exists, the first value is discarded and replaced with the given value.
Definition at line 815 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), QHttp::get(), QHttp::head(), QHttp::post(), setContentLength(), setContentType(), and QHttpPGHRequest::start().
Sets the header entries to be the list of key value pairs in values.
Definition at line 834 of file qhttp.cpp.
|
virtual |
Returns a string representation of the HTTP header.
The string is suitable for use by the constructor that takes a QString. It consists of lines with the format: key, colon, space, value, "\r\n".
Reimplemented in QHttpRequestHeader, and QHttpResponseHeader.
Definition at line 923 of file qhttp.cpp.
Referenced by QHttpResponseHeader::toString(), and QHttpRequestHeader::toString().
Returns the first value for the entry with the given key.
If no entry has this key, an empty string is returned.
Definition at line 732 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotConnected(), QHttpPrivate::_q_slotReadyRead(), contentLength(), contentType(), setValue(), and QHttpSocketEngine::slotSocketReadNotification().
Returns all the entries in the header.
Definition at line 852 of file qhttp.cpp.
Referenced by operator=(), QAuthenticatorPrivate::parseHttpResponse(), QHttpHeader(), and setValues().
|
protected |