Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Added WebServerResponse::writeBinary to allow writing binary contents #288

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,15 @@ void WebServerResponse::write(const QString &body)
mg_write(m_conn, data.constData(), data.size());
}

void WebServerResponse::writeBinary(const QString &body)
{
if (!m_headersSent) {
writeHead(m_statusCode, m_headers);
}
const QByteArray data = body.toAscii();
mg_write(m_conn, data.constData(), data.size());
}

void WebServerResponse::close()
{
m_close->release();
Expand Down
2 changes: 2 additions & 0 deletions src/webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public slots:
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);
/// sends @p binary data to client and makes sure the headers are send beforehand
void writeBinary(const QString &data);

/**
* Closes the request once all data has been written to the client.
Expand Down