From b958102dfa36a3554911adb8fdb21375f0ecb48c Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 3 Dec 2009 09:46:12 +0100 Subject: QNAM: Add priority to the API and use it for HTTP QHttpNetworkRequest and other classes already knew about the priority. Change QNetworkRequest to export this as API. It will be used in WebKit to tag high priority html, javascript and css files as such. Reviewed-By: Markus Goetz --- src/network/access/qnetworkaccesshttpbackend.cpp | 14 ++++++++++ src/network/access/qnetworkrequest.cpp | 34 +++++++++++++++++++++++- src/network/access/qnetworkrequest.h | 9 +++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 91f9189..a42044c 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -467,10 +467,24 @@ void QNetworkAccessHttpBackend::validateCache(QHttpNetworkRequest &httpRequest, loadedFromCache = false; } +static QHttpNetworkRequest::Priority convert(const QNetworkRequest::Priority& prio) +{ + switch (prio) { + case QNetworkRequest::LowPriority: + return QHttpNetworkRequest::LowPriority; + case QNetworkRequest::HighPriority: + return QHttpNetworkRequest::HighPriority; + case QNetworkRequest::NormalPriority: + default: + return QHttpNetworkRequest::NormalPriority; + } +} + void QNetworkAccessHttpBackend::postRequest() { bool loadedFromCache = false; QHttpNetworkRequest httpRequest; + httpRequest.setPriority(convert(request().priority())); switch (operation()) { case QNetworkAccessManager::GetOperation: httpRequest.setOperation(QHttpNetworkRequest::Get); diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 923f2e3..55643e4 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -218,8 +218,9 @@ class QNetworkRequestPrivate: public QSharedData, public QNetworkHeadersPrivate { public: inline QNetworkRequestPrivate() + : priority(QNetworkRequest::NormalPriority) #ifndef QT_NO_OPENSSL - : sslConfiguration(0) + , sslConfiguration(0) #endif { qRegisterMetaType(); } ~QNetworkRequestPrivate() @@ -234,6 +235,7 @@ public: : QSharedData(other), QNetworkHeadersPrivate(other) { url = other.url; + priority = other.priority; #ifndef QT_NO_OPENSSL sslConfiguration = 0; @@ -245,12 +247,14 @@ public: inline bool operator==(const QNetworkRequestPrivate &other) const { return url == other.url && + priority == other.priority && rawHeaders == other.rawHeaders && attributes == other.attributes; // don't compare cookedHeaders } QUrl url; + QNetworkRequest::Priority priority; #ifndef QT_NO_OPENSSL mutable QSslConfiguration *sslConfiguration; #endif @@ -516,6 +520,34 @@ QObject *QNetworkRequest::originatingObject() const return d->originatingObject.data(); } +/*! + \since 4.7 + + Return the priority of this request. + + \sa setPriority() +*/ +QNetworkRequest::Priority QNetworkRequest::priority() const +{ + return d->priority; +} + +/*! + \since 4.7 + + Set the priority of this request. + + \note The priority is only a hint to the network access manager. + It can use it or not. Currently it is used for HTTP to + decide which request should be sent first to a server. + + \sa priority() +*/ +void QNetworkRequest::setPriority(Priority priority) +{ + d->priority = priority; +} + static QByteArray headerName(QNetworkRequest::KnownHeaders header) { switch (header) { diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index 62c6dda..6fd8dba 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -89,6 +89,12 @@ public: AlwaysCache }; + enum Priority { + HighPriority = 1, + NormalPriority = 3, + LowPriority = 5 + }; + explicit QNetworkRequest(const QUrl &url = QUrl()); QNetworkRequest(const QNetworkRequest &other); ~QNetworkRequest(); @@ -123,6 +129,9 @@ public: void setOriginatingObject(QObject *object); QObject *originatingObject() const; + Priority priority() const; + void setPriority(Priority priority); + private: QSharedDataPointer d; friend class QNetworkRequestPrivate; -- cgit v0.12