Skip to content

Commit

Permalink
Merge pull request #48 from bookboon/hotfix/header-class
Browse files Browse the repository at this point in the history
Hotfix/header class
  • Loading branch information
lkm committed Feb 14, 2020
2 parents 8f95365 + e375691 commit e22a7aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Client/BasicAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private function decodeHeaders(string $headers) : array

$headerKey = trim(substr($header, 0, $separator));
$headerKey = implode('-', array_map('ucfirst', explode('-', $headerKey)));
$headerArray[strtolower($headerKey)] = trim(substr($header, $separator + 1));
$headerArray[$headerKey] = trim(substr($header, $separator + 1));
}

return $headerArray;
Expand Down
9 changes: 7 additions & 2 deletions src/Client/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class Headers implements ArrayAccess

public function __construct(array $headers = [])
{
$this->headers = $headers;
foreach ($headers as $k => $v) {
$this->offsetSet($k, $v);
}

$this->set(static::HEADER_XFF, $this->getRemoteAddress() ?? '');
}

Expand Down Expand Up @@ -152,7 +155,9 @@ public function offsetGet($offset)
*/
public function offsetSet($offset, $value)
{
$this->headers[strtolower($offset)] = $value;
if (is_string($offset) && $offset !== '') {
$this->headers[strtolower($offset)] = $value;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Client/OauthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ protected function normalizeHeaders(array $headers) : array
{
$returnHeaders = [];
foreach ($headers as $key => $header) {
$returnHeaders[strtolower($key)] = $header[0] ?? $header;
$returnHeaders[$key] = $header[0] ?? $header;
}

return $returnHeaders;
Expand Down
6 changes: 3 additions & 3 deletions tests/Client/BasicAuthClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testBadAuthentication()
public function testNonExistingHeader()
{
$headers = "HTTP/1.1 200 OK\n Content-Type: application/json; charset=utf-8\nServer: Microsoft-IIS/8.0";
$result = \Helpers::invokeMethod(self::$client, 'getResponseHeader', [[$headers], 'location']);
$result = \Helpers::invokeMethod(self::$client, 'getResponseHeader', [[$headers], 'Location']);

$this->assertEmpty($result);
}
Expand All @@ -51,7 +51,7 @@ public function testValidHeader()
{
$headers = "HTTP/1.1 200 OK\n Content-Type: application/json; charset=utf-8\nServer: Microsoft-IIS/8.0\nLocation: http://bookboon.com";
$headerArray = \Helpers::invokeMethod(self::$client, 'decodeHeaders', [$headers]);
$result = $headerArray['location'];
$result = $headerArray['Location'];

$this->assertEquals('http://bookboon.com', $result);
}
Expand Down Expand Up @@ -79,6 +79,6 @@ public function testNotSupportedMethods($method)
if (in_array($method, ['setAct', 'isCorrectState'])) {
$param = 'a';
}
self::$client->$method($param, "b");
self::$client->$method($param, 'b');
}
}
2 changes: 1 addition & 1 deletion tests/Client/BookboonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BookboonResponseTest extends TestCase
{
public function testRedirectResponse() {
$testUrl = 'http://test.com';
$bResponse = new BookboonResponse('', 302, ['location' => $testUrl]);
$bResponse = new BookboonResponse('', 302, ['Location' => $testUrl]);

$this->assertEquals(['url' => $testUrl], $bResponse->getReturnArray());
}
Expand Down

0 comments on commit e22a7aa

Please sign in to comment.