Qt 4.8
Public Types | Public Functions | Static Public Functions | Public Variables | Private Functions | List of all members
QNetworkHeadersPrivate Class Reference

#include <qnetworkrequest_p.h>

Inheritance diagram for QNetworkHeadersPrivate:
QHttpPartPrivate QNetworkReplyPrivate QNetworkRequestPrivate QNetworkReplyDataImplPrivate QNetworkReplyFileImplPrivate QNetworkReplyImplPrivate

Public Types

typedef QHash< QNetworkRequest::Attribute, QVariantAttributesMap
 
typedef QHash< QNetworkRequest::KnownHeaders, QVariantCookedHeadersMap
 
typedef QPair< QByteArray, QByteArrayRawHeaderPair
 
typedef QList< RawHeaderPairRawHeadersList
 

Public Functions

RawHeadersList allRawHeaders () const
 
RawHeadersList::ConstIterator findRawHeader (const QByteArray &key) const
 
QList< QByteArrayrawHeadersKeys () const
 
void setAllRawHeaders (const RawHeadersList &list)
 Sets the internal raw headers list to match list. More...
 
void setCookedHeader (QNetworkRequest::KnownHeaders header, const QVariant &value)
 
void setRawHeader (const QByteArray &key, const QByteArray &value)
 

Static Public Functions

static QDateTime fromHttpDate (const QByteArray &value)
 
static QByteArray toHttpDate (const QDateTime &dt)
 

Public Variables

AttributesMap attributes
 
CookedHeadersMap cookedHeaders
 
QWeakPointer< QObjectoriginatingObject
 
RawHeadersList rawHeaders
 

Private Functions

void parseAndSetHeader (const QByteArray &key, const QByteArray &value)
 
void setRawHeaderInternal (const QByteArray &key, const QByteArray &value)
 

Detailed Description

Definition at line 66 of file qnetworkrequest_p.h.

Typedefs

◆ AttributesMap

Definition at line 72 of file qnetworkrequest_p.h.

◆ CookedHeadersMap

Definition at line 71 of file qnetworkrequest_p.h.

◆ RawHeaderPair

Definition at line 69 of file qnetworkrequest_p.h.

◆ RawHeadersList

Definition at line 70 of file qnetworkrequest_p.h.

Functions

◆ allRawHeaders()

QNetworkHeadersPrivate::RawHeadersList QNetworkHeadersPrivate::allRawHeaders ( ) const

Definition at line 853 of file qnetworkrequest.cpp.

854 {
855  return rawHeaders;
856 }

◆ findRawHeader()

QNetworkHeadersPrivate::RawHeadersList::ConstIterator QNetworkHeadersPrivate::findRawHeader ( const QByteArray key) const

Definition at line 842 of file qnetworkrequest.cpp.

Referenced by QNetworkAccessHttpBackend::fetchCacheMetaData(), QNetworkRequest::hasRawHeader(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), QNetworkRequest::rawHeader(), and QNetworkAccessHttpBackend::replyDownloadMetaData().

843 {
846  for ( ; it != end; ++it)
847  if (qstricmp(it->first.constData(), key.constData()) == 0)
848  return it;
849 
850  return end; // not found
851 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
Q_CORE_EXPORT int qstricmp(const char *, const char *)
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ fromHttpDate()

QDateTime QNetworkHeadersPrivate::fromHttpDate ( const QByteArray value)
static

Definition at line 1026 of file qnetworkrequest.cpp.

Referenced by QNetworkAccessHttpBackend::fetchCacheMetaData(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), and parseHttpDate().

1027 {
1028  // HTTP dates have three possible formats:
1029  // RFC 1123/822 - ddd, dd MMM yyyy hh:mm:ss "GMT"
1030  // RFC 850 - dddd, dd-MMM-yy hh:mm:ss "GMT"
1031  // ANSI C's asctime - ddd MMM d hh:mm:ss yyyy
1032  // We only handle them exactly. If they deviate, we bail out.
1033 
1034  int pos = value.indexOf(',');
1035  QDateTime dt;
1036 #ifndef QT_NO_DATESTRING
1037  if (pos == -1) {
1038  // no comma -> asctime(3) format
1040  } else {
1041  // Use sscanf over QLocal/QDateTimeParser for speed reasons. See the
1042  // QtWebKit performance benchmarks to get an idea.
1043  if (pos == 3) {
1044  char month_name[4];
1045  int day, year, hour, minute, second;
1046  if (sscanf(value.constData(), "%*3s, %d %3s %d %d:%d:%d 'GMT'", &day, month_name, &year, &hour, &minute, &second) == 6)
1047  dt = QDateTime(QDate(year, name_to_month(month_name), day), QTime(hour, minute, second));
1048  } else {
1049  QLocale c = QLocale::c();
1050  // eat the weekday, the comma and the space following it
1051  QString sansWeekday = QString::fromLatin1(value.constData() + pos + 2);
1052  // must be RFC 850 date
1053  dt = c.toDateTime(sansWeekday, QLatin1String("dd-MMM-yy hh:mm:ss 'GMT'"));
1054  }
1055  }
1056 #endif // QT_NO_DATESTRING
1057 
1058  if (dt.isValid())
1059  dt.setTimeSpec(Qt::UTC);
1060  return dt;
1061 }
unsigned char c[8]
Definition: qnumeric_p.h:62
QDateTime toDateTime(const QString &string, FormatType format=LongFormat) const
Parses the date/time string given in string and returns the time.
Definition: qlocale.cpp:1649
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static int name_to_month(const char *month_str)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDateTime fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the QDateTime represented by the string, using the format given, or an invalid datetime if th...
Definition: qdatetime.cpp:3487
The QTime class provides clock time functions.
Definition: qdatetime.h:148
void setTimeSpec(Qt::TimeSpec spec)
Sets the time specification used in this datetime to spec.
Definition: qdatetime.cpp:2431
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
Definition: qlocale.h:773
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ parseAndSetHeader()

void QNetworkHeadersPrivate::parseAndSetHeader ( const QByteArray key,
const QByteArray value 
)
private

Definition at line 946 of file qnetworkrequest.cpp.

947 {
948  // is it a known header?
950  if (parsedKey != QNetworkRequest::KnownHeaders(-1)) {
951  if (value.isNull()) {
952  cookedHeaders.remove(parsedKey);
953  } else if (parsedKey == QNetworkRequest::ContentLengthHeader
955  // Only set the cooked header "Content-Length" once.
956  // See bug QTBUG-15311
957  } else {
958  cookedHeaders.insert(parsedKey, parseHeaderValue(parsedKey, value));
959  }
960 
961  }
962 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
KnownHeaders
List of known header types that QNetworkRequest parses.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
CookedHeadersMap cookedHeaders
static QNetworkRequest::KnownHeaders parseHeaderName(const QByteArray &headerName)
static QVariant parseHeaderValue(QNetworkRequest::KnownHeaders header, const QByteArray &value)

◆ rawHeadersKeys()

QList< QByteArray > QNetworkHeadersPrivate::rawHeadersKeys ( ) const

Definition at line 858 of file qnetworkrequest.cpp.

Referenced by QNetworkRequest::rawHeaderList().

859 {
860  QList<QByteArray> result;
862  end = rawHeaders.constEnd();
863  for ( ; it != end; ++it)
864  result << it->first;
865 
866  return result;
867 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ setAllRawHeaders()

void QNetworkHeadersPrivate::setAllRawHeaders ( const RawHeadersList list)

Sets the internal raw headers list to match list.

Warning
This function is not part of the public interface. The cooked headers will also be updated.

If list contains duplicates, they will be stored, but only the first one is usually accessed.

Definition at line 890 of file qnetworkrequest.cpp.

Referenced by QNetworkAccessHttpBackend::fetchCacheMetaData(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), and QNetworkAccessHttpBackend::replyDownloadMetaData().

891 {
893  rawHeaders = list;
894 
897  for ( ; it != end; ++it)
898  parseAndSetHeader(it->first, it->second);
899 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
void parseAndSetHeader(const QByteArray &key, const QByteArray &value)
CookedHeadersMap cookedHeaders
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ setCookedHeader()

void QNetworkHeadersPrivate::setCookedHeader ( QNetworkRequest::KnownHeaders  header,
const QVariant value 
)

Definition at line 901 of file qnetworkrequest.cpp.

Referenced by QHttpPart::setHeader(), QNetworkRequest::setHeader(), and QNetworkAccessBackend::setHeader().

903 {
904  QByteArray name = headerName(header);
905  if (name.isEmpty()) {
906  // headerName verifies that \a header is a known value
907  qWarning("QNetworkRequest::setHeader: invalid header value KnownHeader(%d) received", header);
908  return;
909  }
910 
911  if (value.isNull()) {
913  cookedHeaders.remove(header);
914  } else {
915  QByteArray rawValue = headerValue(header, value);
916  if (rawValue.isEmpty()) {
917  qWarning("QNetworkRequest::setHeader: QVariant of type %s cannot be used with header %s",
918  value.typeName(), name.constData());
919  return;
920  }
921 
922  setRawHeaderInternal(name, rawValue);
923  cookedHeaders.insert(header, value);
924  }
925 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
CookedHeadersMap cookedHeaders
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value)
void setRawHeaderInternal(const QByteArray &key, const QByteArray &value)

◆ setRawHeader()

void QNetworkHeadersPrivate::setRawHeader ( const QByteArray key,
const QByteArray value 
)

Definition at line 869 of file qnetworkrequest.cpp.

Referenced by QNetworkAccessHttpBackend::fetchCacheMetaData(), QHttpPart::setRawHeader(), QNetworkRequest::setRawHeader(), and QNetworkAccessBackend::setRawHeader().

870 {
871  if (key.isEmpty())
872  // refuse to accept an empty raw header
873  return;
874 
875  setRawHeaderInternal(key, value);
876  parseAndSetHeader(key, value);
877 }
void parseAndSetHeader(const QByteArray &key, const QByteArray &value)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void setRawHeaderInternal(const QByteArray &key, const QByteArray &value)

◆ setRawHeaderInternal()

void QNetworkHeadersPrivate::setRawHeaderInternal ( const QByteArray key,
const QByteArray value 
)
private

Definition at line 927 of file qnetworkrequest.cpp.

928 {
930  while (it != rawHeaders.end()) {
931  if (qstricmp(it->first.constData(), key.constData()) == 0)
932  it = rawHeaders.erase(it);
933  else
934  ++it;
935  }
936 
937  if (value.isNull())
938  return; // only wanted to erase key
939 
940  RawHeaderPair pair;
941  pair.first = key;
942  pair.second = value;
943  rawHeaders.append(pair);
944 }
#define it(className, varName)
QPair< QByteArray, QByteArray > RawHeaderPair
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
int key
Q_CORE_EXPORT int qstricmp(const char *, const char *)

◆ toHttpDate()

QByteArray QNetworkHeadersPrivate::toHttpDate ( const QDateTime dt)
static

Definition at line 1063 of file qnetworkrequest.cpp.

Referenced by headerValue(), and QNetworkAccessHttpBackend::loadFromCacheIfAllowed().

1064 {
1065  return QLocale::c().toString(dt, QLatin1String("ddd, dd MMM yyyy hh:mm:ss 'GMT'"))
1066  .toLatin1();
1067 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition: qlocale.cpp:1295
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
Definition: qlocale.h:773

Properties

◆ attributes

AttributesMap QNetworkHeadersPrivate::attributes

◆ cookedHeaders

CookedHeadersMap QNetworkHeadersPrivate::cookedHeaders

◆ originatingObject

QWeakPointer<QObject> QNetworkHeadersPrivate::originatingObject

◆ rawHeaders

RawHeadersList QNetworkHeadersPrivate::rawHeaders

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