summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorTapani Mikola <tapani.mikola@nokia.com>2009-09-10 19:38:30 (GMT)
committerTapani Mikola <tapani.mikola@nokia.com>2009-09-18 07:02:04 (GMT)
commit6c52d48a5ed07a3ed21f5b74315ba6fcf06eaada (patch)
treee2f5c9ac18e88e4899a1c7362e18f20f9babe5ce /src/declarative/qml
parent6d0211d01269273392c0ce9997987e5d68e4d114 (diff)
downloadQt-6c52d48a5ed07a3ed21f5b74315ba6fcf06eaada.zip
Qt-6c52d48a5ed07a3ed21f5b74315ba6fcf06eaada.tar.gz
Qt-6c52d48a5ed07a3ed21f5b74315ba6fcf06eaada.tar.bz2
Implementations of getAllResponseHeaders () and getResponseHeader ().
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlxmlhttprequest.cpp73
1 files changed, 69 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp
index 0cfd794..0b6353a 100644
--- a/src/declarative/qml/qmlxmlhttprequest.cpp
+++ b/src/declarative/qml/qmlxmlhttprequest.cpp
@@ -913,6 +913,8 @@ public:
void open(const QString &, const QUrl &);
void addHeader(const QString &, const QString &);
+ QString header(const QString &name);
+ QString headers();
void send(const QByteArray &);
void abort();
@@ -932,6 +934,11 @@ private:
QUrl m_url;
QByteArray m_responseEntityBody;
+ typedef QPair<QByteArray, QByteArray> HeaderPair;
+ typedef QList<HeaderPair> HeadersList;
+ HeadersList m_headersList;
+ void fillHeadersList();
+
void dispatchCallback();
QScriptValue m_callback;
@@ -1012,6 +1019,42 @@ void QmlXMLHttpRequest::addHeader(const QString &name, const QString &value)
}
}
+QString QmlXMLHttpRequest::header(const QString &name)
+{
+ QByteArray utfname = name.toUtf8();
+
+ foreach (const HeaderPair &header, m_headersList) {
+ if (header.first == utfname)
+ return QString::fromUtf8(header.second);
+ }
+ return QString();
+}
+
+QString QmlXMLHttpRequest::headers()
+{
+ QString ret;
+
+ foreach (const HeaderPair &header, m_headersList) {
+ if (ret.length())
+ ret.append(QString::fromUtf8(" "));
+ ret.append(QString::fromUtf8(header.first));
+ ret.append(QString::fromUtf8(": "));
+ ret.append(QString::fromUtf8(header.second));
+ }
+ return ret;
+}
+
+void QmlXMLHttpRequest::fillHeadersList()
+{
+ QList<QByteArray> headerList = m_network->rawHeaderList();
+
+ m_headersList.clear();
+ foreach (const QByteArray &header, headerList) {
+ HeaderPair pair (header, m_network->rawHeader(header));
+ m_headersList << pair;
+ }
+}
+
void QmlXMLHttpRequest::send(const QByteArray &data)
{
m_errorFlag = false;
@@ -1067,6 +1110,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes)
// ### We assume if this is called the headers are now available
if (m_state < HeadersReceived) {
m_state = HeadersReceived;
+ fillHeadersList ();
dispatchCallback();
}
@@ -1096,6 +1140,7 @@ void QmlXMLHttpRequest::finished()
if (m_state < HeadersReceived) {
m_state = HeadersReceived;
+ fillHeadersList ();
dispatchCallback();
}
m_responseEntityBody.append(m_network->readAll());
@@ -1260,16 +1305,36 @@ static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngi
static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine)
{
- // ### Implement
+ QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject());
+ if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object"));
- return engine->undefinedValue();
+ if (context->argumentCount() != 1)
+ return context->throwError(QScriptContext::SyntaxError, QLatin1String("Incorrect argument count"));
+
+ if (request->readyState() != QmlXMLHttpRequest::Loading &&
+ request->readyState() != QmlXMLHttpRequest::Done &&
+ request->readyState() != QmlXMLHttpRequest::HeadersReceived)
+ return context->throwError(INVALID_STATE_ERR, "Invalid state");
+
+ QString headerName = context->argument(0).toString();
+
+ return QScriptValue(request->header(headerName));
}
static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *context, QScriptEngine *engine)
{
- // ### Implement
+ QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject());
+ if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object"));
- return engine->undefinedValue();
+ if (context->argumentCount() != 0)
+ return context->throwError(QScriptContext::SyntaxError, QLatin1String("Incorrect argument count"));
+
+ if (request->readyState() != QmlXMLHttpRequest::Loading &&
+ request->readyState() != QmlXMLHttpRequest::Done &&
+ request->readyState() != QmlXMLHttpRequest::HeadersReceived)
+ return context->throwError(INVALID_STATE_ERR, "Invalid state");
+
+ return QScriptValue(request->headers());
}
// XMLHttpRequest properties