Skip to content

Commit

Permalink
add setProxy function
Browse files Browse the repository at this point in the history
  • Loading branch information
d.guskov committed Jul 10, 2014
1 parent adaef21 commit 573c79f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/phantom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,29 @@ bool Phantom::injectJs(const QString &jsFilePath)
return Utils::injectJsInFrame(pre + jsFilePath, libraryPath(), m_page->mainFrame());
}

void Phantom::setProxy(const QString &ip, const qint64 &port, const QString &proxyType, const QString &user, const QString &password)
{
qDebug() << "Set " << proxyType << " proxy to: " << ip << ":" << port;
if (ip.isEmpty()) {
QNetworkProxyFactory::setUseSystemConfiguration(true);
}
else {
QNetworkProxy::ProxyType networkProxyType = QNetworkProxy::HttpProxy;

if (proxyType == "socks5") {
networkProxyType = QNetworkProxy::Socks5Proxy;
}
// Checking for passed proxy user and password
if(!user.isEmpty() && !password.isEmpty()) {
QNetworkProxy proxy(networkProxyType, ip, port, user, password);
QNetworkProxy::setApplicationProxy(proxy);
} else {
QNetworkProxy proxy(networkProxyType, ip, port);
QNetworkProxy::setApplicationProxy(proxy);
}
}
}

void Phantom::exit(int code)
{
if (m_config.debug()) {
Expand Down
9 changes: 9 additions & 0 deletions src/phantom.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ public slots:
*/
void clearCookies();

/**
* Set the application proxy
* @brief setProxy
* @param ip The proxy ip
* @param port The proxy port
* @param proxyType The type of this proxy
*/
void setProxy(const QString &ip, const qint64 &port = 80, const QString &proxyType = "http", const QString &user = NULL, const QString &password = NULL);

// exit() will not exit in debug mode. debugExit() will always exit.
void exit(int code = 0);
void debugExit(int code = 0);
Expand Down

0 comments on commit 573c79f

Please sign in to comment.