Skip to content

Commit

Permalink
fix to deprecated method + more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nassri committed Feb 5, 2015
1 parent 8af870f commit d5a7ad4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Unirest/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public static function send($method, $url, $body = null, $headers = array(), $us
// supporting deprecated http auth method
if (!empty($username)) {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, self::$auth['user'] . ':' . self::$auth['pass']);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
}

if (!empty(self::$auth['user'])) {
Expand Down
10 changes: 9 additions & 1 deletion tests/Unirest/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ public function testGzip()
$this->assertEquals(true, $args->gzipped);
}

public function testBasicAuthentication()
public function testBasicAuthenticationDeprecated()
{
$response = Unirest\Request::get('http://httpbin.org/get', array(), array(), 'user', 'password');
$headers = $response->body->headers;
$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()
{
$response = Unirest\Request::get('http://httpbin.org/get', array(
Expand Down

0 comments on commit d5a7ad4

Please sign in to comment.