3 Commits

Author SHA1 Message Date
Ahmad Nassri
d5a7ad40bd fix to deprecated method + more tests 2015-02-05 13:00:49 -05:00
Ahmad Nassri
8af870ff69 fix depreicated method as well! 2015-02-05 12:53:30 -05:00
Ahmad Nassri
ae01978eb3 php 5.4 cURL does not support setting username and password separately 2015-02-05 12:48:56 -05:00
2 changed files with 12 additions and 7 deletions

View File

@@ -344,15 +344,13 @@ class Request
// supporting deprecated http auth method // supporting deprecated http auth method
if (!empty($username)) { if (!empty($username)) {
curl_setopt($ch, CURLOPT_USERNAME, $username);
curl_setopt($ch, CURLOPT_PASSWORD, $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
} }
if (!empty(self::$auth['user'])) { if (!empty(self::$auth['user'])) {
curl_setopt($ch, CURLOPT_USERNAME, self::$auth['user']);
curl_setopt($ch, CURLOPT_PASSWORD, self::$auth['pass']);
curl_setopt($ch, CURLOPT_HTTPAUTH, self::$auth['method']); curl_setopt($ch, CURLOPT_HTTPAUTH, self::$auth['method']);
curl_setopt($ch, CURLOPT_USERPWD, self::$auth['user'] . ':' . self::$auth['pass']);
} }
if (self::$proxy['address'] !== false) { if (self::$proxy['address'] !== false) {
@@ -362,8 +360,7 @@ class Request
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, self::$proxy['tunnel']); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, self::$proxy['tunnel']);
curl_setopt($ch, CURLOPT_PROXYAUTH, self::$proxy['auth']['method']); curl_setopt($ch, CURLOPT_PROXYAUTH, self::$proxy['auth']['method']);
curl_setopt($ch, CURLOPT_PROXYUSERNAME, self::$proxy['auth']['user']); curl_setopt($ch, CURLOPT_PROXYUSERPWD, self::$proxy['auth']['user'] . ':' . self::$proxy['auth']['pass']);
curl_setopt($ch, CURLOPT_PROXYPASSWORD, self::$proxy['auth']['pass']);
} }
$response = curl_exec($ch); $response = curl_exec($ch);

View File

@@ -71,13 +71,21 @@ class UnirestRequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(true, $args->gzipped); $this->assertEquals(true, $args->gzipped);
} }
public function testBasicAuthentication() public function testBasicAuthenticationDeprecated()
{ {
$response = Unirest\Request::get('http://httpbin.org/get', array(), array(), 'user', 'password'); $response = Unirest\Request::get('http://httpbin.org/get', array(), array(), 'user', 'password');
$headers = $response->body->headers; $headers = $response->body->headers;
$this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $headers->Authorization); $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $headers->Authorization);
} }
public function testBasicAuthentication()
{
Unirest\Request::auth('user', 'password');
$response = Unirest\Request::get('http://httpbin.org/get');
$this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $response->body->headers->Authorization);
}
public function testCustomHeaders() public function testCustomHeaders()
{ {
$response = Unirest\Request::get('http://httpbin.org/get', array( $response = Unirest\Request::get('http://httpbin.org/get', array(