2011-04-09 21:34:04 +04:00
|
|
|
/*
|
|
|
|
This file is part of the PhantomJS project from Ofi Labs.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
2011-08-31 19:29:40 +04:00
|
|
|
Copyright (C) 2011 Ivan De Marino <ivan.de.marino@gmail.com>
|
2011-04-09 21:34:04 +04:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the <organization> nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-04-08 20:55:10 +04:00
|
|
|
#ifndef NETWORKACCESSMANAGER_H
|
|
|
|
#define NETWORKACCESSMANAGER_H
|
|
|
|
|
2011-09-07 03:37:54 +04:00
|
|
|
#include <QAuthenticator>
|
2011-06-08 18:52:19 +04:00
|
|
|
#include <QHash>
|
2011-04-08 20:55:10 +04:00
|
|
|
#include <QNetworkAccessManager>
|
2011-08-14 12:39:02 +04:00
|
|
|
#include <QNetworkReply>
|
2011-06-08 18:57:51 +04:00
|
|
|
#include <QSet>
|
2012-10-17 19:03:22 +04:00
|
|
|
#include <QSslConfiguration>
|
2011-04-08 20:55:10 +04:00
|
|
|
|
2011-09-15 08:41:58 +04:00
|
|
|
class Config;
|
2011-04-12 18:21:09 +04:00
|
|
|
class QNetworkDiskCache;
|
2012-10-17 19:03:22 +04:00
|
|
|
class QSslConfiguration;
|
2011-04-12 18:21:09 +04:00
|
|
|
|
2011-04-08 20:55:10 +04:00
|
|
|
class NetworkAccessManager : public QNetworkAccessManager
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2011-09-15 08:41:58 +04:00
|
|
|
NetworkAccessManager(QObject *parent, const Config *config);
|
2011-09-17 04:34:02 +04:00
|
|
|
void setUserName(const QString &userName);
|
|
|
|
void setPassword(const QString &password);
|
2012-10-17 05:20:21 +04:00
|
|
|
void setMaxAuthAttempts(int maxAttempts);
|
2012-02-19 12:46:08 +04:00
|
|
|
void setCustomHeaders(const QVariantMap &headers);
|
|
|
|
QVariantMap customHeaders() const;
|
2012-09-06 10:33:18 +04:00
|
|
|
|
|
|
|
void setCookieJar(QNetworkCookieJar *cookieJar);
|
2011-04-08 20:55:10 +04:00
|
|
|
|
|
|
|
protected:
|
2011-04-29 12:24:35 +04:00
|
|
|
bool m_ignoreSslErrors;
|
2012-10-17 05:20:21 +04:00
|
|
|
int m_authAttempts;
|
|
|
|
int m_maxAuthAttempts;
|
2011-09-17 04:34:02 +04:00
|
|
|
QString m_userName;
|
|
|
|
QString m_password;
|
2011-04-08 20:55:10 +04:00
|
|
|
QNetworkReply *createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
|
2012-10-17 05:20:21 +04:00
|
|
|
void handleFinished(QNetworkReply *reply, const QVariant &status, const QVariant &statusText);
|
2011-04-08 22:28:39 +04:00
|
|
|
|
2011-06-07 10:56:23 +04:00
|
|
|
signals:
|
|
|
|
void resourceRequested(const QVariant& data);
|
2011-06-08 12:01:30 +04:00
|
|
|
void resourceReceived(const QVariant& data);
|
2011-06-07 10:56:23 +04:00
|
|
|
|
2011-04-08 22:28:39 +04:00
|
|
|
private slots:
|
2011-06-08 12:01:30 +04:00
|
|
|
void handleStarted();
|
2011-04-08 22:28:39 +04:00
|
|
|
void handleFinished(QNetworkReply *reply);
|
2011-09-17 04:34:02 +04:00
|
|
|
void provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator);
|
2012-10-17 19:03:22 +04:00
|
|
|
void handleSslErrors(const QList<QSslError> &errors);
|
2011-06-08 18:52:19 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
QHash<QNetworkReply*, int> m_ids;
|
2011-06-08 18:57:51 +04:00
|
|
|
QSet<QNetworkReply*> m_started;
|
2011-06-08 18:52:19 +04:00
|
|
|
int m_idCounter;
|
2011-09-07 03:36:23 +04:00
|
|
|
QNetworkDiskCache* m_networkDiskCache;
|
2012-02-19 12:46:08 +04:00
|
|
|
QVariantMap m_customHeaders;
|
2012-10-17 19:03:22 +04:00
|
|
|
QSslConfiguration m_sslConfiguration;
|
2011-04-08 20:55:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NETWORKACCESSMANAGER_H
|