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

The QHttpRequestHeader class contains request header information for HTTP. More...

#include <qhttp.h>

Inheritance diagram for QHttpRequestHeader:
QHttpHeader

Public Functions

int majorVersion () const
 Returns the major protocol-version of the HTTP request header. More...
 
QString method () const
 Returns the method of the HTTP request header. More...
 
int minorVersion () const
 Returns the minor protocol-version of the HTTP request header. More...
 
QHttpRequestHeaderoperator= (const QHttpRequestHeader &header)
 Copies the content of header into this QHttpRequestHeader. More...
 
QString path () const
 Returns the request-URI of the HTTP request header. More...
 
 QHttpRequestHeader ()
 Constructs an empty HTTP request header. More...
 
 QHttpRequestHeader (const QString &method, const QString &path, int majorVer=1, int minorVer=1)
 Constructs a HTTP request header for the method method, the request-URI path and the protocol-version majorVer and minorVer. More...
 
 QHttpRequestHeader (const QHttpRequestHeader &header)
 Constructs a copy of header. More...
 
 QHttpRequestHeader (const QString &str)
 Constructs a HTTP request header from the string str. More...
 
void setRequest (const QString &method, const QString &path, int majorVer=1, int minorVer=1)
 This function sets the request method to method, the request-URI to path and the protocol-version to majorVer and minorVer. 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)
 

Additional Inherited Members

- Protected Variables inherited from QHttpHeader
QScopedPointer< QHttpHeaderPrivated_ptr
 

Detailed Description

The QHttpRequestHeader class contains request header information for HTTP.

Attention
Module: QtNetwork

This class is used in the QHttp class to report the header information if the client requests something from the server.

HTTP requests have a method which describes the request's action. The most common requests are "GET" and "POST". In addition to the request method the header also includes a request-URI to specify the location for the method to use.

The method, request-URI and protocol-version can be set using a constructor or later using setRequest(). The values can be obtained using method(), path(), majorVersion() and minorVersion().

Note that the request-URI must be in the format expected by the HTTP server. That is, all reserved characters must be encoded in HH (where HH are two hexadecimal digits). See QUrl::toPercentEncoding() for more information.

Important inherited functions: setValue() and value().

See also
QHttpResponseHeader QHttp

Definition at line 147 of file qhttp.h.

Constructors and Destructors

◆ QHttpRequestHeader() [1/4]

QHttpRequestHeader::QHttpRequestHeader ( )

Constructs an empty HTTP request header.

Definition at line 1279 of file qhttp.cpp.

1281 {
1282  setValid(false);
1283 }
void setValid(bool)
Definition: qhttp.cpp:720
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578

◆ QHttpRequestHeader() [2/4]

QHttpRequestHeader::QHttpRequestHeader ( const QString method,
const QString path,
int  majorVer = 1,
int  minorVer = 1 
)

Constructs a HTTP request header for the method method, the request-URI path and the protocol-version majorVer and minorVer.

The path argument must be properly encoded for an HTTP request.

Definition at line 1291 of file qhttp.cpp.

1293 {
1295  d->m = method;
1296  d->p = path;
1297  d->majVer = majorVer;
1298  d->minVer = minorVer;
1299 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QString path() const
Returns the request-URI of the HTTP request header.
Definition: qhttp.cpp:1375
QString method() const
Returns the method of the HTTP request header.
Definition: qhttp.cpp:1364
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578

◆ QHttpRequestHeader() [3/4]

QHttpRequestHeader::QHttpRequestHeader ( const QHttpRequestHeader header)

Constructs a copy of header.

Definition at line 1304 of file qhttp.cpp.

1305  : QHttpHeader(*new QHttpRequestHeaderPrivate, header)
1306 {
1308  d->m = header.d_func()->m;
1309  d->p = header.d_func()->p;
1310  d->majVer = header.d_func()->majVer;
1311  d->minVer = header.d_func()->minVer;
1312 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
QHttpHeader()
Constructs an empty HTTP header.
Definition: qhttp.cpp:578

◆ QHttpRequestHeader() [4/4]

QHttpRequestHeader::QHttpRequestHeader ( const QString str)

Constructs a HTTP request header from the string str.

The str should consist of one or more "\r\n" delimited lines; the first line should be the request-line (format: method, space, request-URI, space HTTP-version); each of the remaining lines should have the format key, colon, space, value.

Definition at line 1335 of file qhttp.cpp.

1337 {
1338  parse(str);
1339 }
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

Functions

◆ majorVersion()

int QHttpRequestHeader::majorVersion ( ) const
virtual

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

See also
minorVersion() method() path() setRequest()

Implements QHttpHeader.

Definition at line 1386 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest(), and QHttpPrivate::addRequest().

1387 {
1388  Q_D(const QHttpRequestHeader);
1389  return d->majVer;
1390 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ method()

QString QHttpRequestHeader::method ( ) const

Returns the method of the HTTP request header.

See also
path() majorVersion() minorVersion() setRequest()

Definition at line 1364 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest(), QHttpPrivate::addRequest(), QHttpRequestHeader(), and setRequest().

1365 {
1366  Q_D(const QHttpRequestHeader);
1367  return d->m;
1368 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ minorVersion()

int QHttpRequestHeader::minorVersion ( ) const
virtual

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

See also
majorVersion() method() path() setRequest()

Implements QHttpHeader.

Definition at line 1397 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest(), and QHttpPrivate::addRequest().

1398 {
1399  Q_D(const QHttpRequestHeader);
1400  return d->minVer;
1401 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ operator=()

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

Copies the content of header into this QHttpRequestHeader.

Definition at line 1317 of file qhttp.cpp.

1318 {
1320  QHttpHeader::operator=(header);
1321  d->m = header.d_func()->m;
1322  d->p = header.d_func()->p;
1323  d->majVer = header.d_func()->majVer;
1324  d->minVer = header.d_func()->minVer;
1325  return *this;
1326 }
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 QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ parseLine()

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

Reimplemented from QHttpHeader.

Definition at line 1405 of file qhttp.cpp.

1406 {
1408  if (number != 0)
1409  return QHttpHeader::parseLine(line, number);
1410 
1411  QStringList lst = line.simplified().split(QLatin1String(" "));
1412  if (lst.count() > 0) {
1413  d->m = lst[0];
1414  if (lst.count() > 1) {
1415  d->p = lst[1];
1416  if (lst.count() > 2) {
1417  QString v = lst[2];
1418  if (v.length() >= 8 && v.left(5) == QLatin1String("HTTP/") &&
1419  v[5].isDigit() && v[6] == QLatin1Char('.') && v[7].isDigit()) {
1420  d->majVer = v[5].toLatin1() - '0';
1421  d->minVer = v[7].toLatin1() - '0';
1422  return true;
1423  }
1424  }
1425  }
1426  }
1427 
1428  return false;
1429 }
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 length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
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
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ path()

QString QHttpRequestHeader::path ( ) const

Returns the request-URI of the HTTP request header.

See also
method() majorVersion() minorVersion() setRequest()

Definition at line 1375 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest(), QHttpPrivate::addRequest(), QHttpRequestHeader(), and setRequest().

1376 {
1377  Q_D(const QHttpRequestHeader);
1378  return d->p;
1379 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ setRequest()

void QHttpRequestHeader::setRequest ( const QString method,
const QString path,
int  majorVer = 1,
int  minorVer = 1 
)

This function sets the request method to method, the request-URI to path and the protocol-version to majorVer and minorVer.

The path argument must be properly encoded for an HTTP request.

See also
method() path() majorVersion() minorVersion()

Definition at line 1349 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest(), and QHttpPrivate::addRequest().

1350 {
1352  setValid(true);
1353  d->m = method;
1354  d->p = path;
1355  d->majVer = majorVer;
1356  d->minVer = minorVer;
1357 }
double d
Definition: qnumeric_p.h:62
void setValid(bool)
Definition: qhttp.cpp:720
#define Q_D(Class)
Definition: qglobal.h:2482
QString path() const
Returns the request-URI of the HTTP request header.
Definition: qhttp.cpp:1375
QString method() const
Returns the method of the HTTP request header.
Definition: qhttp.cpp:1364
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ toString()

QString QHttpRequestHeader::toString ( ) const
virtual

Reimplemented Function

Reimplemented from QHttpHeader.

Definition at line 1433 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotConnected().

1434 {
1435  Q_D(const QHttpRequestHeader);
1436  QString first(QLatin1String("%1 %2"));
1437  QString last(QLatin1String(" HTTP/%3.%4\r\n%5\r\n"));
1438  return first.arg(d->m).arg(d->p) +
1439  last.arg(d->majVer).arg(d->minVer).arg(QHttpHeader::toString());
1440 }
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 QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

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