Skip to content

Commit

Permalink
Merge headers with server global header values (bshaffer#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Nov 20, 2017
1 parent d158878 commit 89d3745
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/OAuth2/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public function initialize(array $query = array(), array $request = array(), arr
$this->files = $files;
$this->server = $server;
$this->content = $content;
$this->headers = is_null($headers) ? $this->getHeadersFromServer($this->server) : $headers;

if ($headers === null) {
$headers = array();
}

$this->headers = $headers + $this->getHeadersFromServer($this->server);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/OAuth2/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ public function testRequestReturnsPostParamIfNoQueryParamAvailable()
$this->assertEquals('correct', $request->query('client_id', $request->request('client_id')));
}

public function testRequestHasHeadersAndServerHeaders()
{
$request = new Request(
array(),
array(),
array(),
array(),
array(),
array('CONTENT_TYPE' => 'text/xml', 'PHP_AUTH_USER' => 'client_id', 'PHP_AUTH_PW' => 'client_pass'),
null,
array('CONTENT_TYPE' => 'application/json')
);

$this->assertSame('client_id', $request->headers('PHP_AUTH_USER'));
$this->assertSame('client_pass', $request->headers('PHP_AUTH_PW'));
$this->assertSame('application/json', $request->headers('CONTENT_TYPE'));
}

private function getTestServer($config = array())
{
$storage = Bootstrap::getInstance()->getMemoryStorage();
Expand Down

0 comments on commit 89d3745

Please sign in to comment.