summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkaccessdatabackend.cpp
diff options
context:
space:
mode:
authorThorvald Natvig <slicer@users.sourceforge.net>2009-12-02 19:26:38 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-12-02 19:26:38 (GMT)
commitc0d237b7aa6e0257e3c3eee7336deaed1cf68252 (patch)
tree2b967178643c8deaf4951ee6421bb696fd11b4b7 /src/network/access/qnetworkaccessdatabackend.cpp
parent0fc7c731b47d7984ab8039f70561ad559a0bd36d (diff)
downloadQt-c0d237b7aa6e0257e3c3eee7336deaed1cf68252.zip
Qt-c0d237b7aa6e0257e3c3eee7336deaed1cf68252.tar.gz
Qt-c0d237b7aa6e0257e3c3eee7336deaed1cf68252.tar.bz2
Move data: decoding to function
Merge-request: 1560 Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Diffstat (limited to 'src/network/access/qnetworkaccessdatabackend.cpp')
-rw-r--r--src/network/access/qnetworkaccessdatabackend.cpp62
1 files changed, 15 insertions, 47 deletions
diff --git a/src/network/access/qnetworkaccessdatabackend.cpp b/src/network/access/qnetworkaccessdatabackend.cpp
index feec5b6..cada338 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