mirror of https://github.com/vitalif/phantomjs
Implement WebServerResponse::setEncoding in order to allow binary encoding to be sent.
Fixes http://code.google.com/p/phantomjs/issues/detail?id=5051.8
parent
302050e0ce
commit
78e72312dc
|
@ -287,6 +287,7 @@ WebServerResponse::WebServerResponse(mg_connection* conn, QSemaphore* close)
|
|||
, m_conn(conn)
|
||||
, m_statusCode(200)
|
||||
, m_headersSent(false)
|
||||
, m_isBinary(false)
|
||||
, m_close(close)
|
||||
{
|
||||
}
|
||||
|
@ -399,16 +400,26 @@ void WebServerResponse::writeHead(int statusCode, const QVariantMap &headers)
|
|||
mg_write(m_conn, "\r\n", 2);
|
||||
}
|
||||
|
||||
void WebServerResponse::write(const QString &body)
|
||||
void WebServerResponse::write(const QVariant &body)
|
||||
{
|
||||
if (!m_headersSent) {
|
||||
writeHead(m_statusCode, m_headers);
|
||||
}
|
||||
///TODO: encoding?!
|
||||
const QByteArray data = body.toUtf8();
|
||||
|
||||
QByteArray data = m_isBinary ? body.toByteArray() : body.toString().toUtf8();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void WebServerResponse::close()
|
||||
{
|
||||
m_close->release();
|
||||
|
|
|
@ -112,7 +112,9 @@ public slots:
|
|||
/// send @p headers to client with status code @p statusCode
|
||||
void writeHead(int statusCode, const QVariantMap &headers);
|
||||
/// sends @p data to client and makes sure the headers are send beforehand
|
||||
void write(const QString &data);
|
||||
void write(const QVariant &data);
|
||||
// sets @p as encoding used to output data
|
||||
void setEncoding(const QString &encoding);
|
||||
|
||||
/**
|
||||
* Closes the request once all data has been written to the client.
|
||||
|
@ -152,6 +154,7 @@ private:
|
|||
int m_statusCode;
|
||||
QVariantMap m_headers;
|
||||
bool m_headersSent;
|
||||
bool m_isBinary;
|
||||
QSemaphore* m_close;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue