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 proxy support #80

Merged
merged 1 commit into from
Jun 27, 2013
Merged
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
25 changes: 25 additions & 0 deletions src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,31 @@ public function withStrictSSL()
{
return $this->strictSSL(true);
}

/**
* Use proxy configuration
* @return Request this
* @param string $proxy_host Hostname or address of the proxy
* @param number $proxy_port Port of the proxy. Default 80
* @param string $auth_type Authentication type or null. Accepted values are CURLAUTH_BASIC, CURLAUTH_NTLM. Default null, no authentication
* @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){
$this->addOnCurlOption(CURLOPT_PROXY, "{$proxy_host}:{$proxy_port}");
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;
}

/**
* @return is this request setup for using proxy?
*/
public function hasProxy(){
return is_string($this->additional_curl_opts[CURLOPT_PROXY]);
}

/**
* Determine how/if we use the built in serialization by
Expand Down