Qt 4.8
Public Functions | Protected Functions | Friends | List of all members
QHttpResponseHeader Class Reference

The QHttpResponseHeader class contains response header information for HTTP. More...

#include <qhttp.h>

Inheritance diagram for QHttpResponseHeader:
QHttpHeader

Public Functions

int majorVersion () const
 Returns the major protocol-version of the HTTP response header. More...
 
int minorVersion () const
 Returns the minor protocol-version of the HTTP response header. More...
 
QHttpResponseHeaderoperator= (const QHttpResponseHeader &header)
 Copies the contents of header into this QHttpResponseHeader. More...
 
 QHttpResponseHeader ()
 Constructs an empty HTTP response header. More...
 
 QHttpResponseHeader (const QHttpResponseHeader &header)
 Constructs a copy of header. More...
 
 QHttpResponseHeader (const QString &str)
 Constructs a HTTP response header from the string str. More...
 
 QHttpResponseHeader (int code, const QString &text=QString(), int majorVer=1, int minorVer=1)
 Constructs a QHttpResponseHeader, setting the status code to code, the reason phrase to text and the protocol-version to majorVer and minorVer. More...
 
QString reasonPhrase () const
 Returns the reason phrase of the HTTP response header. More...
 
void setStatusLine (int code, const QString &text=QString(), int majorVer=1, int minorVer=1)
 Sets the status code to code, the reason phrase to text and the protocol-version to majorVer and minorVer. More...
 
int statusCode () const
 Returns the status code of the HTTP response header. More...
 
QString toString () const
 Reimplemented Function More...
 
- Public Functions inherited from QHttpHeader
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...
 
QHttpHeaderoperator= (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...
 
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 parseLine (const QString &line, int number)
 
- Protected Functions inherited from QHttpHeader
bool parse (const QString &str)
 Parses the HTTP header string str for header fields and adds the keys/values it finds. More...
 
 QHttpHeader (QHttpHeaderPrivate &dd, const QString &str=QString())
 
 QHttpHeader (QHttpHeaderPrivate &dd, const QHttpHeader &header)
 
void setValid (bool)
 

Friends

class QHttpPrivate
 

Additional Inherited Members

- Protected Variables inherited from QHttpHeader
QScopedPointer< QHttpHeaderPrivated_ptr
 

Detailed Description

The QHttpResponseHeader class contains response header information for HTTP.

Attention
Module: QtNetwork

This class is used by the QHttp class to report the header information that the client received from the server.

HTTP responses have a status code that indicates the status of the response. This code is a 3-digit integer result code (for details see to RFC 1945). In addition to the status code, you can also specify a human-readable text that describes the reason for the code ("reason phrase"). This class allows you to get the status code and the reason phrase.

See also
QHttpRequestHeader, QHttp, {HTTP Example}

Definition at line 119 of file qhttp.h.

Constructors and Destructors

◆ QHttpResponseHeader() [1/4]

QHttpResponseHeader::QHttpResponseHeader ( )

Constructs an empty HTTP response header.

Definition at line 1055 of file qhttp.cpp.

1057 {
1058  setValid(false);
1059 }
void setValid(bool)
Definition: qhttp.cpp:720
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578

◆ QHttpResponseHeader() [2/4]

QHttpResponseHeader::QHttpResponseHeader ( const QHttpResponseHeader header)

Constructs a copy of header.

Definition at line 1064 of file qhttp.cpp.

1065  : QHttpHeader(*new QHttpResponseHeaderPrivate, header)
1066 {
1068  d->statCode = header.d_func()->statCode;
1069  d->reasonPhr = header.d_func()->reasonPhr;
1070  d->majVer = header.d_func()->majVer;
1071  d->minVer = header.d_func()->minVer;
1072 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ QHttpResponseHeader() [3/4]

QHttpResponseHeader::QHttpResponseHeader ( const QString str)

Constructs a HTTP response header from the string str.

The string is parsed and the information is set. The str should consist of one or more "\r\n" delimited lines; the first line should be the status-line (format: HTTP-version, space, status-code, space, reason-phrase); each of remaining lines should have the format key, colon, space, value.

Definition at line 1096 of file qhttp.cpp.

1098 {
1099  parse(str);
1100 }
bool parse(const QString &str)
Parses the HTTP header string str for header fields and adds the keys/values it finds.
Definition: qhttp.cpp:678
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578

◆ QHttpResponseHeader() [4/4]

QHttpResponseHeader::QHttpResponseHeader ( int  code,
const QString text = QString(),
int  majorVer = 1,
int  minorVer = 1 
)

Constructs a QHttpResponseHeader, setting the status code to code, the reason phrase to text and the protocol-version to majorVer and minorVer.

Since
4.1
See also
statusCode() reasonPhrase() majorVersion() minorVersion()

Definition at line 1114 of file qhttp.cpp.

1116 {
1117  setStatusLine(code, text, majorVer, minorVer);
1118 }
void setStatusLine(int code, const QString &text=QString(), int majorVer=1, int minorVer=1)
Sets the status code to code, the reason phrase to text and the protocol-version to majorVer and mino...
Definition: qhttp.cpp:1131
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578

Functions

◆ majorVersion()

int QHttpResponseHeader::majorVersion ( ) const
virtual

Returns the major protocol-version of the HTTP response header.

See also
minorVersion() statusCode() reasonPhrase()

Implements QHttpHeader.

Definition at line 1168 of file qhttp.cpp.

Referenced by QHttpSocketEngine::slotSocketReadNotification().

1169 {
1170  Q_D(const QHttpResponseHeader);
1171  return d->majVer;
1172 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ minorVersion()

int QHttpResponseHeader::minorVersion ( ) const
virtual

Returns the minor protocol-version of the HTTP response header.

See also
majorVersion() statusCode() reasonPhrase()

Implements QHttpHeader.

Definition at line 1179 of file qhttp.cpp.

Referenced by QHttpSocketEngine::slotSocketReadNotification().

1180 {
1181  Q_D(const QHttpResponseHeader);
1182  return d->minVer;
1183 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ operator=()

QHttpResponseHeader & QHttpResponseHeader::operator= ( const QHttpResponseHeader header)

Copies the contents of header into this QHttpResponseHeader.

Definition at line 1077 of file qhttp.cpp.

1078 {
1080  QHttpHeader::operator=(header);
1081  d->statCode = header.d_func()->statCode;
1082  d->reasonPhr = header.d_func()->reasonPhr;
1083  d->majVer = header.d_func()->majVer;
1084  d->minVer = header.d_func()->minVer;
1085  return *this;
1086 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QHttpHeader & operator=(const QHttpHeader &h)
Assigns h and returns a reference to this http header.
Definition: qhttp.cpp:647
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ parseLine()

bool QHttpResponseHeader::parseLine ( const QString line,
int  number 
)
protectedvirtual
Warning
This function is not part of the public interface.

Reimplemented from QHttpHeader.

Definition at line 1187 of file qhttp.cpp.

1188 {
1190  if (number != 0)
1191  return QHttpHeader::parseLine(line, number);
1192 
1193  QString l = line.simplified();
1194  if (l.length() < 10)
1195  return false;
1196 
1197  if (l.left(5) == QLatin1String("HTTP/") && l[5].isDigit() && l[6] == QLatin1Char('.') &&
1198  l[7].isDigit() && l[8] == QLatin1Char(' ') && l[9].isDigit()) {
1199  d->majVer = l[5].toLatin1() - '0';
1200  d->minVer = l[7].toLatin1() - '0';
1201 
1202  int pos = l.indexOf(QLatin1Char(' '), 9);
1203  if (pos != -1) {
1204  d->reasonPhr = l.mid(pos + 1);
1205  d->statCode = l.mid(9, pos - 9).toInt();
1206  } else {
1207  d->statCode = l.mid(9).toInt();
1208  d->reasonPhr.clear();
1209  }
1210  } else {
1211  return false;
1212  }
1213 
1214  return true;
1215 }
double d
Definition: qnumeric_p.h:62
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.
Definition: qhttp.cpp:905
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
QFactoryLoader * l
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ reasonPhrase()

QString QHttpResponseHeader::reasonPhrase ( ) const

Returns the reason phrase of the HTTP response header.

See also
statusCode() majorVersion() minorVersion()

Definition at line 1157 of file qhttp.cpp.

1158 {
1159  Q_D(const QHttpResponseHeader);
1160  return d->reasonPhr;
1161 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ setStatusLine()

void QHttpResponseHeader::setStatusLine ( int  code,
const QString text = QString(),
int  majorVer = 1,
int  minorVer = 1 
)

Sets the status code to code, the reason phrase to text and the protocol-version to majorVer and minorVer.

Since
4.1
See also
statusCode() reasonPhrase() majorVersion() minorVersion()

Definition at line 1131 of file qhttp.cpp.

Referenced by QHttpResponseHeader().

1132 {
1134  setValid(true);
1135  d->statCode = code;
1136  d->reasonPhr = text;
1137  d->majVer = majorVer;
1138  d->minVer = minorVer;
1139 }
double d
Definition: qnumeric_p.h:62
void setValid(bool)
Definition: qhttp.cpp:720
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119
#define text
Definition: qobjectdefs.h:80

◆ statusCode()

int QHttpResponseHeader::statusCode ( ) const

Returns the status code of the HTTP response header.

See also
reasonPhrase() majorVersion() minorVersion()

Definition at line 1146 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotReadyRead(), and QHttpSocketEngine::slotSocketReadNotification().

1147 {
1148  Q_D(const QHttpResponseHeader);
1149  return d->statCode;
1150 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ toString()

QString QHttpResponseHeader::toString ( ) const
virtual

Reimplemented Function

Reimplemented from QHttpHeader.

Definition at line 1219 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotReadyRead().

1220 {
1221  Q_D(const QHttpResponseHeader);
1222  QString ret(QLatin1String("HTTP/%1.%2 %3 %4\r\n%5\r\n"));
1223  return ret.arg(d->majVer).arg(d->minVer).arg(d->statCode).arg(d->reasonPhr).arg(QHttpHeader::toString());
1224 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QString toString() const
Returns a string representation of the HTTP header.
Definition: qhttp.cpp:923
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

Friends and Related Functions

◆ QHttpPrivate

friend class QHttpPrivate
friend

Definition at line 143 of file qhttp.h.


The documentation for this class was generated from the following files: