summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2010-02-11 06:32:04 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2010-02-11 06:32:04 (GMT)
commit8e72075b8333dcefaa7ddbaeb0bc7ae45d42ff1e (patch)
treeb8b69f812095df8bf780f88302c7784c4d2e18e0 /src/network
parent34450eb48e56677395601bf155a6a05752b326ad (diff)
parentdbfe5f81e300de3a43311197826f23ff031b4b23 (diff)
downloadQt-8e72075b8333dcefaa7ddbaeb0bc7ae45d42ff1e.zip
Qt-8e72075b8333dcefaa7ddbaeb0bc7ae45d42ff1e.tar.gz
Qt-8e72075b8333dcefaa7ddbaeb0bc7ae45d42ff1e.tar.bz2
Merge remote branch 'origin/master' into bearermanagement/integration
Conflicts: configure
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qnetworkaccessdatabackend.cpp62
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp14
-rw-r--r--src/network/access/qnetworkreply.cpp15
-rw-r--r--src/network/access/qnetworkreply.h3
-rw-r--r--src/network/access/qnetworkrequest.cpp45
-rw-r--r--src/network/access/qnetworkrequest.h9
6 files changed, 100 insertions, 48 deletions
diff --git a/src/network/access/qnetworkaccessdatabackend.cpp b/src/network/access/qnetworkaccessdatabackend.cpp
index 52c554f..a2e7ef5 100644
--- a/src/network/access/qnetworkaccessdatabackend.cpp
+++ b/src/network/access/qnetworkaccessdatabackend.cpp
@@ -43,6 +43,7 @@
#include "qnetworkrequest.h"
#include "qnetworkreply.h"
#include "qurlinfo.h"
+#include "private/qdataurl_p.h"
QT_BEGIN_NAMESPACE
@@ -78,53 +79,20 @@ void QNetworkAccessDataBackend::open()
return;
}
- if (uri.host().isEmpty()) {
- setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/plain;charset=US-ASCII"));
-
- // the following would have been the correct thing, but
- // reality often differs from the specification. People have
- // data: URIs with ? and #
- //QByteArray data = QByteArray::fromPercentEncoding(uri.encodedPath());
- QByteArray data = QByteArray::fromPercentEncoding(uri.toEncoded());
-
- // remove the data: scheme
- data.remove(0, 5);
-
- // parse it:
- int pos = data.indexOf(',');
- if (pos != -1) {
- QByteArray payload = data.mid(pos + 1);
- data.truncate(pos);
- data = data.trimmed();
-
- // find out if the payload is encoded in Base64
- if (data.endsWith(";base64")) {
- payload = QByteArray::fromBase64(payload);
- data.chop(7);
- }
-
- if (data.toLower().startsWith("charset")) {
- int i = 7; // strlen("charset")
- while (data.at(i) == ' ')
- ++i;
- if (data.at(i) == '=')
- data.prepend("text/plain;");
- }
-
- if (!data.isEmpty())
- setHeader(QNetworkRequest::ContentTypeHeader, data.trimmed());
-
- setHeader(QNetworkRequest::ContentLengthHeader, payload.size());
- emit metaDataChanged();
-
- QByteDataBuffer list;
- list.append(payload);
- payload.clear(); // important because of implicit sharing!
- writeDownstreamData(list);
-
- finished();
- return;
- }
+ QPair<QString, QByteArray> decoded = qDecodeDataUrl(uri);
+
+ if (! decoded.first.isNull()) {
+ setHeader(QNetworkRequest::ContentTypeHeader, decoded.first);
+ setHeader(QNetworkRequest::ContentLengthHeader, decoded.second.size());
+ emit metaDataChanged();
+
+ QByteDataBuffer list;
+ list.append(decoded.second);
+ decoded.second.clear(); // important because of implicit sharing!
+ writeDownstreamData(list);
+
+ finished();
+ return;
}
// something wrong with this URI
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index 61a95fe..8e02723 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -480,10 +480,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/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp
index dd5cace..c8b8c1f 100644
--- a/src/network/access/qnetworkreply.cpp
+++ b/src/network/access/qnetworkreply.cpp
@@ -538,6 +538,21 @@ QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const
return QByteArray();
}
+/*! \typedef QNetworkReply::RawHeaderPair
+
+ RawHeaderPair is a QPair<QByteArray, QByteArray> where the first
+ QByteArray is the header name and the second is the header.
+ */
+
+/*!
+ Returns a list of raw header pairs.
+ */
+const QList<QNetworkReply::RawHeaderPair>& QNetworkReply::rawHeaderPairs() const
+{
+ Q_D(const QNetworkReply);
+ return d->rawHeaders;
+}
+
/*!
Returns a list of headers fields that were sent by the remote
server, in the order that they were sent. Duplicate headers are
diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h
index b39557a..acb7379 100644
--- a/src/network/access/qnetworkreply.h
+++ b/src/network/access/qnetworkreply.h
@@ -129,6 +129,9 @@ public:
QList<QByteArray> rawHeaderList() const;
QByteArray rawHeader(const QByteArray &headerName) const;
+ typedef QPair<QByteArray, QByteArray> RawHeaderPair;
+ const QList<RawHeaderPair>& rawHeaderPairs() const;
+
// attributes
QVariant attribute(QNetworkRequest::Attribute code) const;
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index a2bef67..b8438a2 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<QNetworkRequest>(); }
~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,45 @@ 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;
+}
+
+/*! \enum QNetworkRequest::Priority
+
+ \since 4.7
+
+ This enum lists the possible network request priorities.
+
+ \value HighPriority High priority
+ \value NormalPriority Normal priority
+ \value LowPriority Low priority
+ */
+
+/*!
+ \since 4.7
+
+ Set the priority of this request to \a priority.
+
+ \note The \a 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 fe01f8c..bc2d9da 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<QNetworkRequestPrivate> d;
friend class QNetworkRequestPrivate;