Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for proxy type #131

Merged
merged 1 commit into from
Jul 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Httpful/Proxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Httpful;

if (!defined('CURLPROXY_SOCKS4')) {
define('CURLPROXY_SOCKS4', 4);
}

/**
* Class to organize the Proxy stuff a bit more
*/
class Proxy
{
const HTTP = CURLPROXY_HTTP;
const SOCKS4 = CURLPROXY_SOCKS4;
const SOCKS5 = CURLPROXY_SOCKS5;
}
23 changes: 22 additions & 1 deletion src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,37 @@ public function withStrictSSL()
* @param string $auth_username Authentication username. Default null
* @param string $auth_password Authentication password. Default null
*/
public function useProxy($proxy_host, $proxy_port = 80, $auth_type = null, $auth_username = null, $auth_password = null)
public function useProxy($proxy_host, $proxy_port = 80, $auth_type = null, $auth_username = null, $auth_password = null, $proxy_type = Proxy::HTTP)
{
$this->addOnCurlOption(CURLOPT_PROXY, "{$proxy_host}:{$proxy_port}");
$this->addOnCurlOption(CURLOPT_PROXYTYPE, $proxy_type);
if (in_array($auth_type, array(CURLAUTH_BASIC,CURLAUTH_NTLM))) {
$this->addOnCurlOption(CURLOPT_PROXYAUTH, $auth_type)
->addOnCurlOption(CURLOPT_PROXYUSERPWD, "{$auth_username}:{$auth_password}");
}
return $this;
}

/**
* Shortcut for useProxy to configure SOCKS 4 proxy
* @see Request::useProxy
* @return Request
*/
public function useSocks4Proxy($proxy_host, $proxy_port = 80, $auth_type = null, $auth_username = null, $auth_password = null)
{
return $this->useProxy($proxy_host, $proxy_port, $auth_type, $auth_username, $auth_password, Proxy::SOCKS4);
}

/**
* Shortcut for useProxy to configure SOCKS 5 proxy
* @see Request::useProxy
* @return Request
*/
public function useSocks5Proxy($proxy_host, $proxy_port = 80, $auth_type = null, $auth_username = null, $auth_password = null)
{
return $this->useProxy($proxy_host, $proxy_port, $auth_type, $auth_username, $auth_password, Proxy::SOCKS5);
}

/**
* @return is this request setup for using proxy?
*/
Expand Down