mirror of https://github.com/vitalif/phantomjs
Generalize WebServer binary data handling into a real encoding support.
http://code.google.com/p/phantomjs/issues/detail?id=5051.8
parent
f70a6ab4ee
commit
8836398825
|
@ -6,6 +6,7 @@ Please see also http://phantomjs.org/releases.html.
|
|||
|
||||
* Integrated GhostDriver as the WebDriver implementation (issue 39)
|
||||
* Added an option to specify the SSL protocol (issue 174)
|
||||
* Added encoding support for WebServer's response (issue 505)
|
||||
* Added process ID (PID) to the System module (issue 769)
|
||||
* Added properties to obtain page and frame title (issue 799)
|
||||
* Added page navigation methods (issue 808)
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "webserver.h"
|
||||
|
||||
#include "encoding.h"
|
||||
#include "mongoose/mongoose.h"
|
||||
|
||||
#include <QByteArray>
|
||||
|
@ -287,7 +288,6 @@ WebServerResponse::WebServerResponse(mg_connection* conn, QSemaphore* close)
|
|||
, m_conn(conn)
|
||||
, m_statusCode(200)
|
||||
, m_headersSent(false)
|
||||
, m_isBinary(false)
|
||||
, m_close(close)
|
||||
{
|
||||
}
|
||||
|
@ -406,18 +406,23 @@ void WebServerResponse::write(const QVariant &body)
|
|||
writeHead(m_statusCode, m_headers);
|
||||
}
|
||||
|
||||
QByteArray data = m_isBinary ? body.toByteArray() : body.toString().toUtf8();
|
||||
QByteArray data;
|
||||
if (m_encoding.isEmpty()) {
|
||||
data = body.toString().toUtf8();
|
||||
} else if (m_encoding.toLower() == "binary") {
|
||||
data = body.toByteArray();
|
||||
} else {
|
||||
Encoding encoding;
|
||||
encoding.setEncoding(m_encoding);
|
||||
data = encoding.encode(body.toString());
|
||||
}
|
||||
|
||||
mg_write(m_conn, data.constData(), data.size());
|
||||
}
|
||||
|
||||
void WebServerResponse::setEncoding(const QString &encoding)
|
||||
{
|
||||
if (encoding.toLower()=="binary") {
|
||||
m_isBinary = true;
|
||||
} else {
|
||||
m_isBinary = false;
|
||||
}
|
||||
m_encoding = encoding;
|
||||
}
|
||||
|
||||
void WebServerResponse::close()
|
||||
|
|
|
@ -154,7 +154,7 @@ private:
|
|||
int m_statusCode;
|
||||
QVariantMap m_headers;
|
||||
bool m_headersSent;
|
||||
bool m_isBinary;
|
||||
QString m_encoding;
|
||||
QSemaphore* m_close;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue