Skip to content

QHttpResponse::allBytesWritten stops emiting when writing #38

@demiantres

Description

@demiantres

The "QHttpResponse::allBytesWritten" signal is emited only a few times when manually writing data to the client. This leads to incomplete downloads.

`req->onEnd(this, req, res {

QFile* f = new QFile(filename); // a file of some MB size
if (f->open(QFile::ReadOnly))
{
	res->addHeader("content-length", QString::number(f->size()).toLatin1());
	res->addHeader("content-type", "application/octet-stream");
	res->addHeader("content-disposition", QStringLiteral("attachment; filename=\"%1\"").arg(info.fileName()).toLatin1());
	//res->addHeader("connection", "Keep-Alive");
	//res->addHeader("keep-alive", "timeout=600, max=100");
	res->setStatusCode(qhttp::ESTATUS_OK);
	connect(res, &QHttpResponse::allBytesWritten, this, [this, f, res] {
		qDebug() << "Write more... " << f->pos(); // called only a few times
		QByteArray data = f->read(50000);
		if (data.length() == 0)
		{
			qDebug() << "END"; // never called
			res->end();
			f->close();
			f->deleteLater();
		}
		else
		{
			res->write(data); // called a few times
		}
	});

	QByteArray data = f->read(50000);
	if (data.length() > 0)
	{
		res->write(data);
		return;
	}
	else
	{
		f->close();
	}
}
f->deleteLater();

});`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions