samedi 9 septembre 2017

How do I intercept and consume a request?

If I a URL with certain path is request to be open, I want to intercept and consume it by my method. I managed to do that by overide QNetworkAccessManager::createRequest() but I don't know what to return when I consume the request. If I return the QNetworkReply which I consume, the method goes in an infine loop being called over and over. How do I fix this?

My code look like this:

QNetworkReply *MyNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
    QNetworkReply *reply = QNetworkAccessManager::createRequest(op, request, outgoingData);
    const QString path = request.url().path();
    if(path == QStringLiteral("/files/xxxx"))
    {
        consume(request);
        return ???
    }

    return reply;
}

Aucun commentaire:

Enregistrer un commentaire