50 #include "QtNetwork/private/qnetworksession_p.h" 53 #include "QtCore/qdatetime.h" 54 #include "QtCore/qelapsedtimer.h" 55 #include "QtNetwork/qsslconfiguration.h" 71 static const char separators[] =
"()<>@,;:\\\"/[]?={}";
72 return isLWS(c) || strchr(separators, c) != 0;
88 if (pos == header.
length())
92 int comma = header.
indexOf(
',', pos);
94 if (comma == pos || equal == pos)
103 if (equal != -1 && end > equal)
112 if (pos == header.
length())
118 if (header.
at(pos) ==
'"') {
124 while (pos < header.
length()) {
125 register char c = header.
at(pos);
129 }
else if (c ==
'\\') {
131 if (pos >= header.
length())
142 while (pos < header.
length()) {
143 register char c = header.
at(pos);
151 result.
insert(key, value);
154 comma = header.
indexOf(
',', pos);
196 , pendingDownloadDataEmissions(new
QAtomicInt())
197 , pendingDownloadProgressEmissions(new
QAtomicInt())
198 , loadingFromCache(false)
199 , usingZerocopyDownloadBuffer(false)
200 #ifndef QT_NO_OPENSSL
201 , pendingSslConfiguration(0), pendingIgnoreAllSslErrors(false)
212 #ifndef QT_NO_OPENSSL 268 if (cacheControl.
contains(
"must-revalidate"))
294 age_value = it->second.toInt();
305 int request_time = now;
306 int response_time = now;
309 int apparent_age =
qMax(0, response_time - date_value);
310 int corrected_received_age =
qMax(apparent_age, age_value);
311 int response_delay = response_time - request_time;
312 int corrected_initial_age = corrected_received_age + response_delay;
313 int resident_time = now - response_time;
314 int current_age = corrected_initial_age + resident_time;
317 if (!expirationDate.
isValid()) {
319 int diff = currentDateTime.
secsTo(lastModified);
320 expirationDate = lastModified;
321 expirationDate.
addSecs(diff / 10);
325 if (dt.
daysTo(currentDateTime) > 1)
333 int freshness_lifetime = dateHeader.
secsTo(expirationDate);
334 bool response_is_fresh = (freshness_lifetime > current_age);
336 bool response_is_fresh = currentDateTime.
secsTo(expirationDate) >= 0;
339 if (!response_is_fresh)
342 #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) 343 qDebug() <<
"response_is_fresh" << CacheLoadControlAttribute;
375 #ifndef QT_NO_NETWORKPROXY 376 qRegisterMetaType<QNetworkProxy>(
"QNetworkProxy");
378 #ifndef QT_NO_OPENSSL 379 qRegisterMetaType<QList<QSslError> >(
"QList<QSslError>");
380 qRegisterMetaType<QSslConfiguration>(
"QSslConfiguration");
382 qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >(
"QList<QPair<QByteArray,QByteArray> >");
383 qRegisterMetaType<QHttpNetworkRequest>(
"QHttpNetworkRequest");
384 qRegisterMetaType<QNetworkReply::NetworkError>(
"QNetworkReply::NetworkError");
385 qRegisterMetaType<QSharedPointer<char> >(
"QSharedPointer<char>");
401 #ifndef QT_NO_NETWORKPROXY 417 transparentProxy = p;
436 bool loadedFromCache =
false;
479 if (loadedFromCache) {
516 if (static_cast<QNetworkRequest::LoadControl>
524 #ifndef QT_NO_BEARERMANAGEMENT 536 #ifndef QT_NO_NETWORKPROXY 541 #ifndef QT_NO_OPENSSL 578 #ifndef QT_NO_OPENSSL 587 #ifndef QT_NO_NETWORKPROXY 592 #ifndef QT_NO_OPENSSL 610 forwardUploadDevice->
setParent(delegate);
617 forwardUploadDevice,
SIGNAL(readyRead()),
726 if (pendingSignals > 0) {
758 switch (statusCode) {
799 for (; it !=
end; ++
it) {
825 bool mustReValidate =
false;
828 if (cacheControl.
contains(
"must-revalidate"))
829 mustReValidate =
true;
837 #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) 838 qDebug() <<
"Received a 304 from" <<
url();
844 if (oldMetaData != metaData)
865 if (pendingSignals > 0) {
884 #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) 888 error(errorCode, errorString);
891 #ifndef QT_NO_OPENSSL 930 qint64 currentUploadDataLength = 0;
933 QByteArray dataArray(data, currentUploadDataLength);
952 #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) 953 qDebug() <<
"Can not send cache, the contents are 0" <<
url();
971 for ( ; it !=
end; ++
it)
980 qRegisterMetaType<QIODevice*>(
"QIODevice*");
984 #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) 985 qDebug() <<
"Successfully sent cache:" <<
url() << contents->
size() <<
"bytes";
1000 #ifndef QT_NO_OPENSSL 1042 (header ==
"connection" 1043 || header ==
"keep-alive" 1044 || header ==
"proxy-authenticate" 1045 || header ==
"proxy-authorization" 1047 || header ==
"trailers" 1048 || header ==
"transfer-encoding" 1049 || header ==
"upgrade");
1056 if (header ==
"date")
1060 if (header ==
"warning") {
1064 && v[1] >=
'0' && v[1] <=
'9' 1065 && v[2] >=
'0' && v[2] <=
'9')
1072 if (header ==
"content-encoding" 1073 || header ==
"content-range" 1074 || header ==
"content-type")
1079 if (header ==
"content-length")
1083 #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) 1088 if (n != o && header !=
"date") {
1098 bool checkExpired =
true;
1106 checkExpired =
false;
1129 canDiskCache =
true;
1135 && it->second ==
"no-cache")
1136 canDiskCache =
false;
1139 if (cacheControl.
contains(
"no-cache"))
1140 canDiskCache =
false;
1141 else if (cacheControl.
contains(
"no-store"))
1142 canDiskCache =
false;
1147 canDiskCache =
false;
1150 if (cacheControl.
contains(
"max-age"))
1151 canDiskCache =
true;
1155 canDiskCache =
false;
1179 QByteArray acceptRangesheaderName(
"Accept-Ranges");
1205 #endif // QT_NO_HTTP QNetworkReply::NetworkError incomingErrorCode
The QVariant class acts like a union for the most common Qt data types.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
int daysTo(const QDateTime &) const
Returns the number of days from this datetime to the other datetime.
virtual void closeDownstreamChannel()
static QHash< QByteArray, QByteArray > parseHttpOptionHeader(const QByteArray &header)
virtual bool reset()=0
Moves the internal read pointer back to the beginning.
void wantUploadDataSlot(qint64)
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
virtual void ignoreSslErrors()
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
virtual void updateMetaData(const QNetworkCacheMetaData &metaData)=0
Updates the cache meta date for the metaData's url to metaData.
#define QT_END_NAMESPACE
This macro expands to.
QNetworkProxy transparentProxy
virtual QNetworkAccessBackend * create(QNetworkAccessManager::Operation op, const QNetworkRequest &request) const
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value)
QSslConfiguration sslConfiguration() const
Returns this network request's SSL configuration.
void setPriority(Priority priority)
The QAtomicInt class provides platform-independent atomic operations on integers. ...
#define it(className, varName)
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw form of header headerName.
QVariant header(QNetworkRequest::KnownHeaders header) const
The QByteArray class provides an array of bytes.
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
void startHttpRequestSynchronously()
QHttpNetworkRequest httpRequest
void setOperation(Operation operation)
QSslConfiguration incomingSslConfiguration
uint toTime_t() const
Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
NetworkError
Indicates all possible error conditions found during the processing of the request.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
void readBufferFreed(qint64 size)
Operation
Indicates the operation this reply is processing.
QString incomingErrorDetail
Priority
This enum lists the possible network request priorities.
QSslConfiguration * pendingSslConfiguration
static LibLoadStatus status
#define Q_ARG(type, data)
QByteArray toLower() const
Returns a lowercase copy of the byte array.
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setPipeliningAllowed(bool b)
void append(QByteDataBuffer &other)
bool loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest)
virtual bool remove(const QUrl &url)=0
Removes the cache entry for url, returning true if success otherwise false.
void httpError(QNetworkReply::NetworkError error, const QString &errorString)
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
void checkForRedirect(const int statusCode)
The QHash class is a template class that provides a hash-table-based dictionary.
QList< QSslError > pendingIgnoreSslErrorsList
void writeDownstreamDataDownloadBuffer(qint64, qint64)
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
qint64 downloadBufferMaximumSize
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
static int nextNonWhitespace(const QByteArray &text, int from)
void quit()
Tells the thread's event loop to exit with return code 0 (success).
const T value(const Key &key) const
Returns the value associated with the key.
virtual void downstreamReadyWrite()
void httpAuthenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *auth)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
bool hasRawHeader(const QByteArray &headerName) const
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
QUrl url() const
Returns the URL this network request is referring to.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
void setParent(QObject *)
Makes the object a child of parent.
virtual const char * readPointer(qint64 maximumLength, qint64 &len)=0
Return a byte pointer for at most maximumLength bytes of that device.
QSharedPointer< QAtomicInt > pendingDownloadDataEmissions
QNetworkAccessManagerPrivate * manager
virtual QIODevice * data(const QUrl &url)=0
Returns the data associated with url.
void haveUploadData(QByteArray dataArray, bool dataAtEnd, qint64 dataSize)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
virtual void copyFinished(QIODevice *)
Q_CORE_EXPORT void qDebug(const char *,...)
static bool toBool(Register *reg, int type, bool *ok=0)
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
void resetUploadDataSlot(bool *r)
void disableReset()
Disable the reset() call, e.
The QNetworkProxy class provides a network layer proxy.
QNonContiguousByteDevice * createUploadByteDevice()
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue=QByteArray()) const
QNetworkReplyImplPrivate * reply
void setUrl(const QUrl &url)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
void setTime_t(uint secsSince1Jan1970UTC)
Sets the date and time given the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const
Capabilities capabilities() const
Returns the capabilities of this proxy server.
bool sendCacheContents(const QNetworkCacheMetaData &metaData)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
QList< QNetworkProxy > proxyList() const
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
static int toInt(const QByteArray &str)
bool isNull() const
Returns true if this is a null QSslConfiguration object.
qulonglong toULongLong(bool *ok=0, int base=10) const
Returns the byte array converted to an {unsigned long long} using base base, which is 10 by default a...
bool usingZerocopyDownloadBuffer
qint64 incomingContentLength
static const char * data(const QByteArray &arr)
static QHttpNetworkRequest::Priority convert(const QNetworkRequest::Priority &prio)
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
static bool isSeparator(register char c)
void setWithCredentials(bool b)
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QNetworkAccessManager::Operation operation() const
Operation operation() const
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
QByteArray synchronousDownloadData
void setDownloadBuffer(QSharedPointer< char > sp, qint64 size)
static bool isLWS(register char c)
QByteArray rawHeader(const QByteArray &headerName) const
The QAuthenticator class provides an authentication object.
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
QAbstractNetworkCache * networkCache() const
int fetchAndAddAcquire(int valueToAdd)
Atomic fetch-and-add.
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
void readBufferSizeChanged(qint64 size)
QByteDataBuffer pendingDownloadData
T * data() const
Returns the value of the pointer referenced by this object.
int length() const
Same as size().
virtual ~QNetworkAccessHttpBackend()
T & first()
Returns a reference to the first item in the list.
const char * constData() const
Returns a pointer to the data stored in the byte array.
void sentUploadDataSlot(qint64)
QSharedPointer< QNonContiguousByteDevice > uploadByteDevice
virtual void setReadBufferSize(qint64 size)
QString scheme() const
Returns the scheme of the URL.
void authenticationRequired(QAuthenticator *auth)
void error(QNetworkReply::NetworkError code, const QString &errorString)
void replySslConfigurationChanged(const QSslConfiguration &)
The QDateTime class provides date and time functions.
QString trimmed(QString source)
QNetworkRequest request() const
virtual bool advanceReadPointer(qint64 amount)=0
The old readPointer is invalid after this call.
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
QSharedPointer< QNetworkSession > networkSession
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
bool isTransparentProxy() const
Returns true if this proxy supports transparent tunneling of TCP connections.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
QNetworkAccessHttpBackend()
QHttpNetworkRequest httpRequest
if(void) toggleToolbarShown
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
virtual void setDownstreamLimited(bool b)
virtual QNetworkCacheMetaData metaData(const QUrl &url)=0
Returns the meta data for the url url.
void writeDownstreamData(QByteDataBuffer &list)
T qvariant_cast(const QVariant &)
QVariant attribute(QNetworkRequest::Attribute code) const
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QSharedPointer< QAtomicInt > pendingDownloadProgress
void replyDownloadProgressSlot(qint64, qint64)
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
QVariant property(const char *name) const
Returns the value of the object's name property.
bool isCachingEnabled() const
QList< QPair< QByteArray, QByteArray > > incomingHeaders
CacheLoadControl
Controls the caching mechanism of QNetworkAccessManager.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
void setCachingEnabled(bool enable)
The QSslConfiguration class holds the configuration and state of an SSL connection.
void setHeaderField(const QByteArray &name, const QByteArray &data)
void replyDownloadMetaData(QList< QPair< QByteArray, QByteArray > >, int, QString, bool, QSharedPointer< char >, qint64)
QList< QByteArray > rawHeaderList() const
Returns a list of all raw headers that are set in this network request.
QThread * thread() const
Returns the thread in which the object lives.
QSharedPointer< QAtomicInt > pendingDownloadProgressEmissions
virtual bool atEnd()=0
Returns true if everything has been read and the read pointer cannot be advanced anymore.
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Q_CORE_EXPORT int qstricmp(const char *, const char *)
virtual qint64 size()=0
Returns the size of the complete device or -1 if unknown.
void replySslErrors(const QList< QSslError > &, bool *, QList< QSslError > *)
char at(int i) const
Returns the character at index position i in the byte array.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
void reserve(int size)
Attempts to allocate memory for at least size bytes.
QString incomingReasonPhrase
virtual void setSslConfiguration(const QSslConfiguration &configuration)
static const KeyPair *const end
The QIODevice class is the base interface class of all I/O devices in Qt.
void setCustomVerb(const QByteArray &customOperation)
The QThread class provides a platform-independent way to manage threads.
virtual void fetchSslConfiguration(QSslConfiguration &configuration) const
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
void deleteLater()
Schedules this object for deletion.
QList< QByteArray > rawHeaderList() const
void clear()
Clears the contents of the byte array and makes it empty.
void replyDownloadData(QByteArray)
void redirectionRequested(const QUrl &destination)
static bool equal(const QChar *a, int l, const char *b)
void sslErrors(const QList< QSslError > &errors)
QSharedPointer< QAtomicInt > pendingDownloadData
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
The QAbstractNetworkCache class provides the interface for cache implementations. ...
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
bool pendingIgnoreAllSslErrors
void setUploadByteDevice(QNonContiguousByteDevice *bd)
virtual void emitReadBufferFreed(qint64 size)
void setResumeOffset(quint64 offset)