summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-03 07:41:24 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-03 07:41:24 (GMT)
commit0d037da6f4a7a7da7ad319265d7abbf41295e082 (patch)
treee7cfdbda968053af36dfa85beb50f40a41bcd3ef /src/declarative/qml
parentcb16e0adba54015963f2cd8a3f0188965c0c9ef8 (diff)
parent142dc7e75faaf76894633851c25a907bd7e8b9b8 (diff)
downloadQt-0d037da6f4a7a7da7ad319265d7abbf41295e082.zip
Qt-0d037da6f4a7a7da7ad319265d7abbf41295e082.tar.gz
Qt-0d037da6f4a7a7da7ad319265d7abbf41295e082.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlxmlhttprequest.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp
index f69f254..2c35ebf 100644
--- a/src/declarative/qml/qmlxmlhttprequest.cpp
+++ b/src/declarative/qml/qmlxmlhttprequest.cpp
@@ -966,12 +966,16 @@ private slots:
void finished();
private:
+ void requestFromUrl(const QUrl &url);
+
State m_state;
bool m_errorFlag;
bool m_sendFlag;
QString m_method;
QUrl m_url;
QByteArray m_responseEntityBody;
+ QByteArray m_data;
+ int m_redirectCount;
typedef QPair<QByteArray, QByteArray> HeaderPair;
typedef QList<HeaderPair> HeadersList;
@@ -1001,7 +1005,7 @@ private:
QmlXMLHttpRequest::QmlXMLHttpRequest()
: m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
- m_network(0), m_nam(0)
+ m_redirectCount(0), m_network(0), m_nam(0)
{
}
@@ -1109,16 +1113,10 @@ void QmlXMLHttpRequest::fillHeadersList()
}
}
-QScriptValue QmlXMLHttpRequest::send(const QByteArray &data)
+void QmlXMLHttpRequest::requestFromUrl(const QUrl &url)
{
- m_errorFlag = false;
- m_sendFlag = true;
-
- QScriptValue cbv = dispatchCallback();
- if (cbv.isError()) return cbv;
-
- m_request.setUrl(m_url);
QNetworkRequest request = m_request;
+ request.setUrl(url);
if(m_method == QLatin1String("POST") ||
m_method == QLatin1String("PUT")) {
QVariant var = request.header(QNetworkRequest::ContentTypeHeader);
@@ -1153,9 +1151,9 @@ QScriptValue QmlXMLHttpRequest::send(const QByteArray &data)
else if (m_method == QLatin1String("HEAD"))
m_network = networkAccessManager()->head(request);
else if(m_method == QLatin1String("POST"))
- m_network = networkAccessManager()->post(request, data);
+ m_network = networkAccessManager()->post(request, m_data);
else if(m_method == QLatin1String("PUT"))
- m_network = networkAccessManager()->put(request, data);
+ m_network = networkAccessManager()->put(request, m_data);
QObject::connect(m_network, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(downloadProgress(qint64)));
@@ -1163,6 +1161,16 @@ QScriptValue QmlXMLHttpRequest::send(const QByteArray &data)
this, SLOT(error(QNetworkReply::NetworkError)));
QObject::connect(m_network, SIGNAL(finished()),
this, SLOT(finished()));
+}
+
+QScriptValue QmlXMLHttpRequest::send(const QByteArray &data)
+{
+ m_errorFlag = false;
+ m_sendFlag = true;
+ m_redirectCount = 0;
+ m_data = data;
+
+ requestFromUrl(m_url);
return QScriptValue();
}
@@ -1224,6 +1232,7 @@ void QmlXMLHttpRequest::error(QNetworkReply::NetworkError error)
m_responseEntityBody = QByteArray();
m_request = QNetworkRequest();
+ m_data.clear();
destroyNetwork();
if (error == QNetworkReply::ContentAccessDenied ||
@@ -1243,9 +1252,19 @@ void QmlXMLHttpRequest::error(QNetworkReply::NetworkError error)
if (cbv.isError()) printError(cbv);
}
+#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION 15
void QmlXMLHttpRequest::finished()
{
- // ### We need to transparently redirect as dictated by the spec
+ m_redirectCount++;
+ if (m_redirectCount < XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = m_network->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = redirect.toUrl();
+ destroyNetwork();
+ requestFromUrl(url);
+ return;
+ }
+ }
m_status =
m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@@ -1259,6 +1278,7 @@ void QmlXMLHttpRequest::finished()
if (cbv.isError()) printError(cbv);
}
m_responseEntityBody.append(m_network->readAll());
+ m_data.clear();
destroyNetwork();
if (m_state < Loading) {
m_state = Loading;