Store response messages as QByteArray

This prevents conversion of QByteArray to QString from truncating content at a null byte in the QByteArray. This truncation can be a problem if the response body is a binary object (e.g. PDF)

Fixes #322
This commit is contained in:
Dan Ivovich 2012-04-17 12:06:12 -04:00
parent 73618220b0
commit 1ef8f4c844
9 changed files with 18 additions and 14 deletions

View File

@ -62,7 +62,7 @@ void Connection::writeResponse(Response *response) {
else
m_socket->write("failure\n");
QByteArray messageUtf8 = response->message().toUtf8();
QByteArray messageUtf8 = response->message();
QString messageLength = QString::number(messageUtf8.size()) + "\n";
m_socket->write(messageLength.toAscii());
m_socket->write(messageUtf8);

View File

@ -55,8 +55,7 @@ void CurrentUrl::start() {
QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
QByteArray encodedBytes = humanUrl.toEncoded();
QString urlString = QString(encodedBytes);
emit finished(new Response(true, urlString));
emit finished(new Response(true, encodedBytes));
}
bool CurrentUrl::wasRegularLoad() {

View File

@ -10,7 +10,7 @@ void Execute::start() {
if (result.isValid()) {
emit finished(new Response(true));
} else {
emit finished(new Response(false, "Javascript failed to execute"));
emit finished(new Response(false, QString("Javascript failed to execute")));
}
}

View File

@ -13,7 +13,7 @@ void Find::start() {
message = result.toString();
emit finished(new Response(true, message));
} else {
emit finished(new Response(false, "Invalid XPath expression"));
emit finished(new Response(false, QString("Invalid XPath expression")));
}
}

View File

@ -50,7 +50,7 @@ void FrameFocus::focusId(QString name) {
void FrameFocus::focusParent() {
if (page()->currentFrame()->parentFrame() == 0) {
emit finished(new Response(false, "Already at parent frame."));
emit finished(new Response(false, QString("Already at parent frame.")));
} else {
page()->currentFrame()->parentFrame()->setFocus();
success();
@ -58,7 +58,7 @@ void FrameFocus::focusParent() {
}
void FrameFocus::frameNotFound() {
emit finished(new Response(false, "Unable to locate frame. "));
emit finished(new Response(false, QString("Unable to locate frame. ")));
}
void FrameFocus::success() {

View File

@ -7,7 +7,6 @@ RequestedUrl::RequestedUrl(WebPage *page, QStringList &arguments, QObject *paren
void RequestedUrl::start() {
QUrl humanUrl = page()->currentFrame()->requestedUrl();
QByteArray encodedBytes = humanUrl.toEncoded();
QString urlString = QString(encodedBytes);
emit finished(new Response(true, urlString));
emit finished(new Response(true, encodedBytes));
}

View File

@ -2,6 +2,11 @@
#include <iostream>
Response::Response(bool success, QString message) {
m_success = success;
m_message = message.toUtf8();
}
Response::Response(bool success, QByteArray message) {
m_success = success;
m_message = message;
}
@ -14,6 +19,6 @@ bool Response::isSuccess() const {
return m_success;
}
QString Response::message() const {
QByteArray Response::message() const {
return m_message;
}

View File

@ -1,13 +1,15 @@
#include <QString>
#include <QByteArray>
class Response {
public:
Response(bool success, QString message);
Response(bool success, QByteArray message);
Response(bool success);
bool isSuccess() const;
QString message() const;
QByteArray message() const;
private:
bool m_success;
QString m_message;
QByteArray m_message;
};

View File

@ -7,7 +7,6 @@ Url::Url(WebPage *page, QStringList &arguments, QObject *parent) : Command(page,
void Url::start() {
QUrl humanUrl = page()->currentFrame()->url();
QByteArray encodedBytes = humanUrl.toEncoded();
QString urlString = QString(encodedBytes);
emit finished(new Response(true, urlString));
emit finished(new Response(true, encodedBytes));
}