Qt 4.8
Functions
qnetworkaccesshttpbackend.cpp File Reference
#include "qnetworkaccesshttpbackend_p.h"
#include "qnetworkaccessmanager_p.h"
#include "qnetworkaccesscache_p.h"
#include "qabstractnetworkcache.h"
#include "qnetworkrequest.h"
#include "qnetworkreply.h"
#include "QtNetwork/private/qnetworksession_p.h"
#include "qnetworkrequest_p.h"
#include "qnetworkcookie_p.h"
#include "QtCore/qdatetime.h"
#include "QtCore/qelapsedtimer.h"
#include "QtNetwork/qsslconfiguration.h"
#include "qhttpthreaddelegate_p.h"
#include "qthread.h"
#include <string.h>

Go to the source code of this file.

Functions

static QHttpNetworkRequest::Priority convert (const QNetworkRequest::Priority &prio)
 
static bool isSeparator (register char c)
 
static QHash< QByteArray, QByteArrayparseHttpOptionHeader (const QByteArray &header)
 

Function Documentation

◆ convert()

static QHttpNetworkRequest::Priority convert ( const QNetworkRequest::Priority prio)
static

◆ isSeparator()

static bool isSeparator ( register char  c)
inlinestatic

Definition at line 69 of file qnetworkaccesshttpbackend.cpp.

Referenced by QComboBoxDelegate::paint(), parseHttpOptionHeader(), and QComboBoxDelegate::sizeHint().

70 {
71  static const char separators[] = "()<>@,;:\\\"/[]?={}";
72  return isLWS(c) || strchr(separators, c) != 0;
73 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static bool isLWS(register char c)

◆ parseHttpOptionHeader()

static QHash<QByteArray, QByteArray> parseHttpOptionHeader ( const QByteArray header)
static

Definition at line 76 of file qnetworkaccesshttpbackend.cpp.

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

77 {
78  // The HTTP header is of the form:
79  // header = #1(directives)
80  // directives = token | value-directive
81  // value-directive = token "=" (token | quoted-string)
83 
84  int pos = 0;
85  while (true) {
86  // skip spaces
87  pos = nextNonWhitespace(header, pos);
88  if (pos == header.length())
89  return result; // end of parsing
90 
91  // pos points to a non-whitespace
92  int comma = header.indexOf(',', pos);
93  int equal = header.indexOf('=', pos);
94  if (comma == pos || equal == pos)
95  // huh? Broken header.
96  return result;
97 
98  // The key name is delimited by either a comma, an equal sign or the end
99  // of the header, whichever comes first
100  int end = comma;
101  if (end == -1)
102  end = header.length();
103  if (equal != -1 && end > equal)
104  end = equal; // equal sign comes before comma/end
105  QByteArray key = QByteArray(header.constData() + pos, end - pos).trimmed().toLower();
106  pos = end + 1;
107 
108  if (uint(equal) < uint(comma)) {
109  // case: token "=" (token | quoted-string)
110  // skip spaces
111  pos = nextNonWhitespace(header, pos);
112  if (pos == header.length())
113  // huh? Broken header
114  return result;
115 
116  QByteArray value;
117  value.reserve(header.length() - pos);
118  if (header.at(pos) == '"') {
119  // case: quoted-string
120  // quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
121  // qdtext = <any TEXT except <">>
122  // quoted-pair = "\" CHAR
123  ++pos;
124  while (pos < header.length()) {
125  register char c = header.at(pos);
126  if (c == '"') {
127  // end of quoted text
128  break;
129  } else if (c == '\\') {
130  ++pos;
131  if (pos >= header.length())
132  // broken header
133  return result;
134  c = header.at(pos);
135  }
136 
137  value += c;
138  ++pos;
139  }
140  } else {
141  // case: token
142  while (pos < header.length()) {
143  register char c = header.at(pos);
144  if (isSeparator(c))
145  break;
146  value += c;
147  ++pos;
148  }
149  }
150 
151  result.insert(key, value);
152 
153  // find the comma now:
154  comma = header.indexOf(',', pos);
155  if (comma == -1)
156  return result; // end of parsing
157  pos = comma + 1;
158  } else {
159  // case: token
160  // key is already set
161  result.insert(key, QByteArray());
162  }
163  }
164 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
static int nextNonWhitespace(const QByteArray &text, int from)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
unsigned int uint
Definition: qglobal.h:996
static bool isSeparator(register char c)
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString trimmed(QString source)
Definition: generator.cpp:233
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
static const KeyPair *const end
static bool equal(const QChar *a, int l, const char *b)
Definition: qurl.cpp:3270