diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2013-01-21 19:45:04 +0100 |
---|---|---|
committer | Pierre Rossi <pierre.rossi@gmail.com> | 2013-11-01 13:57:45 +0100 |
commit | efe2251d0547627ef1877193dc788fc2ab2af939 (patch) | |
tree | b64e17e9f252acdc4368175f9e4bafc2894f8836 | |
parent | 86f3f5331ec7cf7e195d265ad9371dc2ff2218bb (diff) | |
download | qtwebchannel-efe2251d0547627ef1877193dc788fc2ab2af939.tar.gz |
Also add content-length to QWebChannelResponder to make it stabler.
Still, one can trigger XMLHttpRequest errors occasionally e.g.:
POST http://localhost:49158/6e933d76-843e-4b01-b273-fc36b0480ab1/POLL
Unknown error
This will then render the whole QObject bridge useless - I will
investigate.
Change-Id: Ifb7343414dac82e9af0a30ac008c3940283b1ecd
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
-rw-r--r-- | src/qwebchannel.cpp | 18 | ||||
-rw-r--r-- | src/qwebchannel.h | 11 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/qwebchannel.cpp b/src/qwebchannel.cpp index a4c1a49..3b656c1 100644 --- a/src/qwebchannel.cpp +++ b/src/qwebchannel.cpp @@ -70,10 +70,19 @@ void QWebChannelResponder::retain() void QWebChannelResponder::noop() { - send(""); + open(0); + close(); } -void QWebChannelResponder::open() +void QWebChannelResponder::send(const QString& stringData) +{ + const QByteArray data = stringData.toUtf8(); + open(data.length()); + write(data); + close(); +} + +void QWebChannelResponder::open(uint contentLength) { if (!socket || !socket->isOpen()) { qWarning() << "cannot open response - socket is not open anymore"; @@ -84,16 +93,17 @@ void QWebChannelResponder::open() socket->write("HTTP/1.1 200 OK\r\n" "Content-Type: text/json\r\n" + "Content-Length: " + QByteArray::number(contentLength) + "\r\n" "\r\n"); } -void QWebChannelResponder::write(const QString& data) +void QWebChannelResponder::write(const QByteArray& data) { if (!socket || !socket->isOpen()) { qWarning() << "cannot write response - socket is not open anymore"; return; } - socket->write(data.toUtf8()); + socket->write(data); } void QWebChannelResponder::close() diff --git a/src/qwebchannel.h b/src/qwebchannel.h index b564787..12834a8 100644 --- a/src/qwebchannel.h +++ b/src/qwebchannel.h @@ -55,17 +55,12 @@ public: QWebChannelResponder(QTcpSocket* s); public slots: - void open(); - void write(const QString& data); + void open(uint contentLength); + void write(const QByteArray& data); void close(); void retain(); void noop(); - void send(const QString& data) - { - open(); - write(data); - close(); - } + void send(const QString& stringData); private slots: void closeIfNotRetained(); |