Qt 4.8
Public Functions | Protected Functions | Protected Variables | List of all members
QHttpHeader Class Referenceabstract

The QHttpHeader class contains header information for HTTP. More...

#include <qhttp.h>

Inheritance diagram for QHttpHeader:
QHttpRequestHeader QHttpResponseHeader

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...
 
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...
 
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< QHttpHeaderPrivated_ptr
 

Detailed Description

The QHttpHeader class contains header information for HTTP.

Attention
Module: QtNetwork

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:

content-type: text/html

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.

header.setValue("content-type", "text/html");
QString contentType = header.value("content-type");

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.

See also
QHttpRequestHeader QHttpResponseHeader

Definition at line 69 of file qhttp.h.

Constructors and Destructors

◆ QHttpHeader() [1/5]

QHttpHeader::QHttpHeader ( )

Constructs an empty HTTP header.

Definition at line 578 of file qhttp.cpp.

580 {
581  Q_D(QHttpHeader);
582  d->q_ptr = this;
583  d->valid = true;
584 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QHttpHeaderPrivate > d_ptr
Definition: qhttp.h:112
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ QHttpHeader() [2/5]

QHttpHeader::QHttpHeader ( const QHttpHeader header)

Constructs a copy of header.

Definition at line 589 of file qhttp.cpp.

591 {
592  Q_D(QHttpHeader);
593  d->q_ptr = this;
594  d->valid = header.d_func()->valid;
595  d->values = header.d_func()->values;
596 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QHttpHeaderPrivate > d_ptr
Definition: qhttp.h:112
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QPair< QString, QString > > values() const
Returns all the entries in the header.
Definition: qhttp.cpp:852
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ QHttpHeader() [3/5]

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.

608 {
609  Q_D(QHttpHeader);
610  d->q_ptr = this;
611  d->valid = true;
612  parse(str);
613 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QHttpHeaderPrivate > d_ptr
Definition: qhttp.h:112
#define Q_D(Class)
Definition: qglobal.h:2482
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
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ ~QHttpHeader()

QHttpHeader::~QHttpHeader ( )
virtual

Destructor.

Definition at line 640 of file qhttp.cpp.

641 {
642 }

◆ QHttpHeader() [4/5]

QHttpHeader::QHttpHeader ( QHttpHeaderPrivate dd,
const QString str = QString() 
)
protected
Warning
This function is not part of the public interface.

Definition at line 617 of file qhttp.cpp.

618  : d_ptr(&dd)
619 {
620  Q_D(QHttpHeader);
621  d->q_ptr = this;
622  d->valid = true;
623  if (!str.isEmpty())
624  parse(str);
625 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QHttpHeaderPrivate > d_ptr
Definition: qhttp.h:112
#define Q_D(Class)
Definition: qglobal.h:2482
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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ QHttpHeader() [5/5]

QHttpHeader::QHttpHeader ( QHttpHeaderPrivate dd,
const QHttpHeader header 
)
protected
Warning
This function is not part of the public interface.

Definition at line 629 of file qhttp.cpp.

630  : d_ptr(&dd)
631 {
632  Q_D(QHttpHeader);
633  d->q_ptr = this;
634  d->valid = header.d_func()->valid;
635  d->values = header.d_func()->values;
636 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QHttpHeaderPrivate > d_ptr
Definition: qhttp.h:112
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QPair< QString, QString > > values() const
Returns all the entries in the header.
Definition: qhttp.cpp:852
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

Functions

◆ addValue()

void QHttpHeader::addValue ( const QString key,
const QString value 
)

Adds a new entry with the key and value.

Definition at line 843 of file qhttp.cpp.

Referenced by parseLine(), and setValue().

844 {
845  Q_D(QHttpHeader);
846  d->values.append(qMakePair(key, value));
847 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ allValues()

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.

750 {
751  Q_D(const QHttpHeader);
752  QString lowercaseKey = key.toLower();
753  QStringList valueList;
754  QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
755  while (it != d->values.constEnd()) {
756  if ((*it).first.toLower() == lowercaseKey)
757  valueList.append((*it).second);
758  ++it;
759  }
760  return valueList;
761 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ contentLength()

uint QHttpHeader::contentLength ( ) const

Returns the value of the special HTTP header field content-length.

See also
setContentLength() hasContentLength()

Definition at line 956 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotClosed(), and QHttpPrivate::_q_slotReadyRead().

957 {
958  return value(QLatin1String("content-length")).toUInt();
959 }
QString value(const QString &key) const
Returns the first value for the entry with the given key.
Definition: qhttp.cpp:732
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
Definition: qstring.cpp:6120

◆ contentType()

QString QHttpHeader::contentType ( ) const

Returns the value of the special HTTP header field content-type.

See also
setContentType() hasContentType()

Definition at line 988 of file qhttp.cpp.

989 {
990  QString type = value(QLatin1String("content-type"));
991  if (type.isEmpty())
992  return QString();
993 
994  int pos = type.indexOf(QLatin1Char(';'));
995  if (pos == -1)
996  return type;
997 
998  return type.left(pos).trimmed();
999 }
QString value(const QString &key) const
Returns the first value for the entry with the given key.
Definition: qhttp.cpp:732
int type
Definition: qmetatype.cpp:239
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ hasContentLength()

bool QHttpHeader::hasContentLength ( ) const

Returns true if the header has an entry for the special HTTP header field content-length; otherwise returns false.

See also
contentLength() setContentLength()

Definition at line 945 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotReadyRead().

946 {
947  return hasKey(QLatin1String("content-length"));
948 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool hasKey(const QString &key) const
Returns true if the HTTP header has an entry with the given key; otherwise returns false...
Definition: qhttp.cpp:792

◆ hasContentType()

bool QHttpHeader::hasContentType ( ) const

Returns true if the header has an entry for the special HTTP header field content-type; otherwise returns false.

See also
contentType() setContentType()

Definition at line 978 of file qhttp.cpp.

979 {
980  return hasKey(QLatin1String("content-type"));
981 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool hasKey(const QString &key) const
Returns true if the HTTP header has an entry with the given key; otherwise returns false...
Definition: qhttp.cpp:792

◆ hasKey()

bool QHttpHeader::hasKey ( const QString key) const

Returns true if the HTTP header has an entry with the given key; otherwise returns false.

See also
value() setValue() keys()

Definition at line 792 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotClosed(), QHttpPrivate::_q_slotReadyRead(), hasContentLength(), and hasContentType().

793 {
794  Q_D(const QHttpHeader);
795  QString lowercaseKey = key.toLower();
796  QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
797  while (it != d->values.constEnd()) {
798  if ((*it).first.toLower() == lowercaseKey)
799  return true;
800  ++it;
801  }
802  return false;
803 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isValid()

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().

661 {
662  Q_D(const QHttpHeader);
663  return d->valid;
664 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ keys()

QStringList QHttpHeader::keys ( ) const

Returns a list of the keys in the HTTP header.

See also
hasKey()

Definition at line 768 of file qhttp.cpp.

769 {
770  Q_D(const QHttpHeader);
771  QStringList keyList;
772  QSet<QString> seenKeys;
773  QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
774  while (it != d->values.constEnd()) {
775  const QString &key = (*it).first;
776  QString lowercaseKey = key.toLower();
777  if (!seenKeys.contains(lowercaseKey)) {
778  keyList.append(key);
779  seenKeys.insert(lowercaseKey);
780  }
781  ++it;
782  }
783  return keyList;
784 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool contains(const T &value) const
Definition: qset.h:91
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const_iterator insert(const T &value)
Definition: qset.h:179
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ majorVersion()

int QHttpHeader::majorVersion ( ) const
pure virtual

Returns the major protocol-version of the HTTP header.

Implemented in QHttpRequestHeader, and QHttpResponseHeader.

◆ minorVersion()

int QHttpHeader::minorVersion ( ) const
pure virtual

Returns the minor protocol-version of the HTTP header.

Implemented in QHttpRequestHeader, and QHttpResponseHeader.

◆ operator=()

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=().

648 {
649  Q_D(QHttpHeader);
650  d->values = h.d_func()->values;
651  d->valid = h.d_func()->valid;
652  return *this;
653 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QPair< QString, QString > > values() const
Returns all the entries in the header.
Definition: qhttp.cpp:852
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ parse()

bool QHttpHeader::parse ( const QString str)
protected

Parses the HTTP header string str for header fields and adds the keys/values it finds.

Warning
This function is not part of the public interface. If the string is not parsed successfully the QHttpHeader becomes invalid.

Returns true if str was successfully parsed; otherwise returns false.

See also
toString()

Definition at line 678 of file qhttp.cpp.

Referenced by QHttpHeader(), QHttpRequestHeader::QHttpRequestHeader(), and QHttpResponseHeader::QHttpResponseHeader().

679 {
680  Q_D(QHttpHeader);
681  QStringList lst;
682  int pos = str.indexOf(QLatin1Char('\n'));
683  if (pos > 0 && str.at(pos - 1) == QLatin1Char('\r'))
684  lst = str.trimmed().split(QLatin1String("\r\n"));
685  else
686  lst = str.trimmed().split(QLatin1String("\n"));
687  lst.removeAll(QString()); // No empties
688 
689  if (lst.isEmpty())
690  return true;
691 
692  QStringList lines;
694  for (; it != lst.end(); ++it) {
695  if (!(*it).isEmpty()) {
696  if ((*it)[0].isSpace()) {
697  if (!lines.isEmpty()) {
698  lines.last() += QLatin1Char(' ');
699  lines.last() += (*it).trimmed();
700  }
701  } else {
702  lines.append((*it));
703  }
704  }
705  }
706 
707  int number = 0;
708  it = lines.begin();
709  for (; it != lines.end(); ++it) {
710  if (!parseLine(*it, number++)) {
711  d->valid = false;
712  return false;
713  }
714  }
715  return true;
716 }
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
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
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
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
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
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ parseLine()

bool QHttpHeader::parseLine ( const QString line,
int  number 
)
protectedvirtual

Parses the single HTTP header line line which has the format key, colon, space, value, and adds key/value to the headers.

Warning
This function is not part of the public interface. The linenumber is number. Returns true if the line was successfully parsed and the key/value added; otherwise returns false.
See also
parse()

Reimplemented in QHttpRequestHeader, and QHttpResponseHeader.

Definition at line 905 of file qhttp.cpp.

Referenced by parse(), QHttpResponseHeader::parseLine(), and QHttpRequestHeader::parseLine().

906 {
907  int i = line.indexOf(QLatin1Char(':'));
908  if (i == -1)
909  return false;
910 
911  addValue(line.left(i).trimmed(), line.mid(i + 1).trimmed());
912 
913  return true;
914 }
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
void addValue(const QString &key, const QString &value)
Adds a new entry with the key and value.
Definition: qhttp.cpp:843
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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ removeAllValues()

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.

881 {
882  Q_D(QHttpHeader);
883  QString lowercaseKey = key.toLower();
884  QList<QPair<QString, QString> >::Iterator it = d->values.begin();
885  while (it != d->values.end()) {
886  if ((*it).first.toLower() == lowercaseKey) {
887  it = d->values.erase(it);
888  continue;
889  }
890  ++it;
891  }
892 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ removeValue()

void QHttpHeader::removeValue ( const QString key)

Removes the entry with the key key from the HTTP header.

See also
value() setValue()

Definition at line 863 of file qhttp.cpp.

864 {
865  Q_D(QHttpHeader);
866  QString lowercaseKey = key.toLower();
867  QList<QPair<QString, QString> >::Iterator it = d->values.begin();
868  while (it != d->values.end()) {
869  if ((*it).first.toLower() == lowercaseKey) {
870  d->values.erase(it);
871  return;
872  }
873  ++it;
874  }
875 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setContentLength()

void QHttpHeader::setContentLength ( int  len)

Sets the value of the special HTTP header field content-length to len.

See also
contentLength() hasContentLength()

Definition at line 967 of file qhttp.cpp.

968 {
969  setValue(QLatin1String("content-length"), QString::number(len));
970 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setValue(const QString &key, const QString &value)
Sets the value of the entry with the key to value.
Definition: qhttp.cpp:815

◆ setContentType()

void QHttpHeader::setContentType ( const QString type)

Sets the value of the special HTTP header field content-type to type.

See also
contentType() hasContentType()

Definition at line 1007 of file qhttp.cpp.

1008 {
1009  setValue(QLatin1String("content-type"), type);
1010 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setValue(const QString &key, const QString &value)
Sets the value of the entry with the key to value.
Definition: qhttp.cpp:815

◆ setValid()

void QHttpHeader::setValid ( bool  v)
protected
Warning
This function is not part of the public interface.

Definition at line 720 of file qhttp.cpp.

Referenced by QHttpRequestHeader::QHttpRequestHeader(), QHttpResponseHeader::QHttpResponseHeader(), QHttpRequestHeader::setRequest(), and QHttpResponseHeader::setStatusLine().

721 {
722  Q_D(QHttpHeader);
723  d->valid = v;
724 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ setValue()

void QHttpHeader::setValue ( const QString key,
const QString value 
)

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.

See also
value() hasKey() removeValue()

Definition at line 815 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest(), QHttp::get(), QHttp::head(), QHttp::post(), setContentLength(), setContentType(), and QHttpPGHRequest::start().

816 {
817  Q_D(QHttpHeader);
818  QString lowercaseKey = key.toLower();
819  QList<QPair<QString, QString> >::Iterator it = d->values.begin();
820  while (it != d->values.end()) {
821  if ((*it).first.toLower() == lowercaseKey) {
822  (*it).second = value;
823  return;
824  }
825  ++it;
826  }
827  // not found so add
828  addValue(key, value);
829 }
double d
Definition: qnumeric_p.h:62
QString value(const QString &key) const
Returns the first value for the entry with the given key.
Definition: qhttp.cpp:732
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
void addValue(const QString &key, const QString &value)
Adds a new entry with the key and value.
Definition: qhttp.cpp:843
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setValues()

void QHttpHeader::setValues ( const QList< QPair< QString, QString > > &  values)

Sets the header entries to be the list of key value pairs in values.

Definition at line 834 of file qhttp.cpp.

835 {
836  Q_D(QHttpHeader);
837  d->values = values;
838 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QPair< QString, QString > > values() const
Returns all the entries in the header.
Definition: qhttp.cpp:852
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

◆ toString()

QString QHttpHeader::toString ( ) const
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().

924 {
925  Q_D(const QHttpHeader);
926  if (!isValid())
927  return QLatin1String("");
928 
929  QString ret = QLatin1String("");
930 
931  QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
932  while (it != d->values.constEnd()) {
933  ret += (*it).first + QLatin1String(": ") + (*it).second + QLatin1String("\r\n");
934  ++it;
935  }
936  return ret;
937 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
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
bool isValid() const
Returns true if the HTTP header is valid; otherwise returns false.
Definition: qhttp.cpp:660
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ value()

QString QHttpHeader::value ( const QString key) const

Returns the first value for the entry with the given key.

If no entry has this key, an empty string is returned.

See also
setValue() removeValue() hasKey() keys()

Definition at line 732 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotConnected(), QHttpPrivate::_q_slotReadyRead(), contentLength(), contentType(), setValue(), and QHttpSocketEngine::slotSocketReadNotification().

733 {
734  Q_D(const QHttpHeader);
735  QString lowercaseKey = key.toLower();
736  QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
737  while (it != d->values.constEnd()) {
738  if ((*it).first.toLower() == lowercaseKey)
739  return (*it).second;
740  ++it;
741  }
742  return QString();
743 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ values()

QList< QPair< QString, QString > > QHttpHeader::values ( ) const

Returns all the entries in the header.

Definition at line 852 of file qhttp.cpp.

Referenced by operator=(), QAuthenticatorPrivate::parseHttpResponse(), QHttpHeader(), and setValues().

853 {
854  Q_D(const QHttpHeader);
855  return d->values;
856 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttpHeader class contains header information for HTTP.
Definition: qhttp.h:69

Properties

◆ d_ptr

QScopedPointer<QHttpHeaderPrivate> QHttpHeader::d_ptr
protected

Definition at line 112 of file qhttp.h.


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