Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 45 lines (36 sloc) 1.341 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QStringList>

class NetworkAccessManager : public QNetworkAccessManager {

  Q_OBJECT

  struct NetworkResponse {
    int statusCode;
    QList<QNetworkReply::RawHeaderPair> headers;
    NetworkResponse() : statusCode(0) { }
  };

  public:
    NetworkAccessManager(QObject *parent = 0);
    void addHeader(QString key, QString value);
    void resetHeaders();
    void setUserName(const QString &userName);
    void setPassword(const QString &password);
    int statusFor(QUrl url);
    const QList<QNetworkReply::RawHeaderPair> &headersFor(QUrl url);
    void setUrlBlacklist(QStringList urlBlacklist);

  protected:
    QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice * outgoingData);
    QString m_userName;
    QString m_password;
    QList<QUrl> m_urlBlacklist;


  private:
    QHash<QString, QString> m_headers;
    QHash<QUrl, NetworkResponse> m_responses;
    bool isBlacklisted(QUrl url);
    QHash<QUrl, QUrl> m_redirectMappings;

  private slots:
    void provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator);
    void finished(QNetworkReply *);

  signals:
    void requestCreated(QByteArray &url, QNetworkReply *reply);
};
Something went wrong with that request. Please try again.