Skip to content

Commit

Permalink
Merge pull request #89 from RusinovIG/master
Browse files Browse the repository at this point in the history
Fixed setting of default headers array
  • Loading branch information
Ahmad Nassri committed Jan 20, 2016
2 parents da71f06 + ca6a3b1 commit 4a480b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Unirest/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function timeout($seconds)
*/
public static function defaultHeaders($headers)
{
return array_merge(self::$defaultHeaders, $headers);
return self::$defaultHeaders = array_merge(self::$defaultHeaders, $headers);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/Unirest/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ public function testTimeoutFail()
Unirest\Request::timeout(null); // Cleaning timeout for the other tests
}

public function testDefaultHeaders()
{
$defaultHeaders = array(
'header1' => 'Hello',
'header2' => 'world'
);
Unirest\Request::defaultHeaders($defaultHeaders);

$response = Unirest\Request::get('http://mockbin.com/request');

$this->assertEquals(200, $response->code);
$this->assertObjectHasAttribute('header1', $response->body->headers);
$this->assertEquals('Hello', $response->body->headers->header1);
$this->assertObjectHasAttribute('header2', $response->body->headers);
$this->assertEquals('world', $response->body->headers->header2);

Unirest\Request::clearDefaultHeaders();

$response = Unirest\Request::get('http://mockbin.com/request');

$this->assertEquals(200, $response->code);
$this->assertObjectNotHasAttribute('header1', $response->body->headers);
$this->assertObjectNotHasAttribute('header2', $response->body->headers);
}

public function testDefaultHeader()
{
Unirest\Request::defaultHeader('Hello', 'custom');
Expand Down

0 comments on commit 4a480b1

Please sign in to comment.