mirror of
https://github.com/ariya/phantomjs.git
synced 2024-09-11 04:46:09 +03:00
Add the ability to set the proxy server on a per-page-object basis.
Issue: #11667
This commit is contained in:
parent
08081d8672
commit
efd8dedfb5
@ -55,6 +55,7 @@
|
||||
#define PAGE_SETTINGS_JS_ENABLED "javascriptEnabled"
|
||||
#define PAGE_SETTINGS_XSS_AUDITING "XSSAuditingEnabled"
|
||||
#define PAGE_SETTINGS_USER_AGENT "userAgent"
|
||||
#define PAGE_SETTINGS_PROXY "proxy"
|
||||
#define PAGE_SETTINGS_LOCAL_ACCESS_REMOTE "localToRemoteUrlAccessEnabled"
|
||||
#define PAGE_SETTINGS_USERNAME "userName"
|
||||
#define PAGE_SETTINGS_PASSWORD "password"
|
||||
|
@ -420,6 +420,15 @@ void Phantom::setProxy(const QString& ip, const qint64& port, const QString& pro
|
||||
}
|
||||
}
|
||||
|
||||
QString Phantom::proxy()
|
||||
{
|
||||
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
||||
if (proxy.hostName().isEmpty()) {
|
||||
return NULL;
|
||||
}
|
||||
return proxy.hostName() + ":" + QString::number(proxy.port());
|
||||
}
|
||||
|
||||
void Phantom::exit(int code)
|
||||
{
|
||||
if (m_config.debug()) {
|
||||
|
@ -170,6 +170,8 @@ public slots:
|
||||
*/
|
||||
void setProxy(const QString& ip, const qint64& port = 80, const QString& proxyType = "http", const QString& user = NULL, const QString& password = NULL);
|
||||
|
||||
QString proxy();
|
||||
|
||||
// exit() will not exit in debug mode. debugExit() will always exit.
|
||||
void exit(int code = 0);
|
||||
void debugExit(int code = 0);
|
||||
|
@ -55,6 +55,8 @@
|
||||
#include <QDebug>
|
||||
#include <QImageWriter>
|
||||
#include <QUuid>
|
||||
#include <QUrl>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
#include "phantom.h"
|
||||
#include "networkaccessmanager.h"
|
||||
@ -641,6 +643,21 @@ void WebPage::applySettings(const QVariantMap& def)
|
||||
m_networkAccessManager->setResourceTimeout(def[PAGE_SETTINGS_RESOURCE_TIMEOUT].toInt());
|
||||
}
|
||||
|
||||
if (def.contains(PAGE_SETTINGS_PROXY)) {
|
||||
setProxy(def[PAGE_SETTINGS_PROXY].toString());
|
||||
}
|
||||
}
|
||||
|
||||
void WebPage::setProxy(const QString& proxyUrl)
|
||||
{
|
||||
QUrl url(proxyUrl);
|
||||
qDebug() << "Setting proxy to: " << url.scheme() << url.host() << url.port();
|
||||
QNetworkProxy::ProxyType type = QNetworkProxy::HttpProxy;
|
||||
if (url.scheme() == "socks5") {
|
||||
type = QNetworkProxy::Socks5Proxy;
|
||||
}
|
||||
QNetworkProxy proxy(type, url.host(), url.port(), url.userName(), url.password());
|
||||
m_networkAccessManager->setProxy(proxy);
|
||||
}
|
||||
|
||||
QString WebPage::userAgent() const
|
||||
|
@ -501,6 +501,8 @@ public slots:
|
||||
|
||||
void clearMemoryCache();
|
||||
|
||||
void setProxy(const QString& proxyUrl);
|
||||
|
||||
signals:
|
||||
void initialized();
|
||||
void loadStarted();
|
||||
|
Loading…
Reference in New Issue
Block a user