Commit 3888dc6d authored by Soheil Armin's avatar Soheil Armin
Browse files

added chunked data for keep-alive http replies

parent ac508832
......@@ -40,6 +40,7 @@ void QHttpRequest::start()
m_requestBody);
connect(reply,&QNetworkReply::finished,this,&QHttpRequest::processReply);
connect(reply,&QNetworkReply::readyRead,this,&QHttpRequest::processChunk);
}
void QHttpRequest::processReply()
......@@ -49,7 +50,8 @@ void QHttpRequest::processReply()
if (reply == nullptr)
return;
if (reply->error() == QNetworkReply::NoError)
if (reply->error() == QNetworkReply::NoError &&
reply->header(QNetworkRequest::ContentLengthHeader).isValid())
createResponse(reply);
auto httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
......@@ -69,6 +71,17 @@ void QHttpRequest::processReply()
emit finished();
}
void QHttpRequest::processChunk()
{
auto reply = qobject_cast<QNetworkReply *>(sender());
if (reply == nullptr)
return;
if (!reply->header(QNetworkRequest::ContentLengthHeader).isValid()) {
emit dataChunk(reply->readAll());
}
}
QJSValue QHttpRequest::getResponseBody() const
{
return m_responseBody;
......
......@@ -30,6 +30,7 @@ public:
public Q_SLOTS:
void start();
void processReply();
void processChunk();
private:
......@@ -62,6 +63,7 @@ signals:
void headersChanged(const QVariantMap &headers);
void parametersChanged(const QVariantMap &parameters);
void requestBodyChanged(const QByteArray &requestBody);
void dataChunk(const QByteArray &data);
void responseBodyChanged(const QJSValue &responseBody);
void networkErrorChanged(int networkError);
......@@ -70,8 +72,6 @@ signals:
void runningChanged(bool running);
void finished();
void error();
};
static void registerQHttpRequest()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment