Skip to content

Commit

Permalink
Merge pull request #82 from utopia-php/feat-get-request-headers
Browse files Browse the repository at this point in the history
Feat: Request->getHeaders()
  • Loading branch information
eldadfux authored Nov 1, 2022
2 parents 97f64aa + d834e9c commit 8f55a8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ public function getHeader(string $key, string $default = ''): string
return (isset($headers[$key])) ? $headers[$key] : $default;
}

/**
* Get headers
*
* Method for getting all HTTP header parameters.
*
* @return array<string,mixed>
*/
public function getHeaders(): array
{
return $this->generateHeaders();
}

/**
* Set header
*
Expand Down
4 changes: 0 additions & 4 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ public function testCanAddAndExecuteHooks()
$result = \ob_get_contents();
\ob_end_clean();

// var_dump($result);
$this->assertEquals('(init)-x-def-(shutdown)', $result);

// Default Params
Expand All @@ -335,7 +334,6 @@ public function testCanAddAndExecuteHooks()
$result = \ob_get_contents();
\ob_end_clean();

// var_dump($result);
$this->assertEquals('x-def', $result);
}

Expand Down Expand Up @@ -564,8 +562,6 @@ public function testMultipleAliases(string $path, string $expected): void
$result = \ob_get_contents();
\ob_end_clean();

var_dump($result);

$this->assertEquals($expected, $result);
}
}
6 changes: 6 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function testCanGetHeaders()

$this->assertEquals('value1', $this->request->getHeader('custom'));
$this->assertEquals('value2', $this->request->getHeader('custom-new'));

$headers = $this->request->getHeaders();
$this->assertIsArray($headers);
$this->assertCount(2, $headers);
$this->assertEquals('value1', $headers['custom']);
$this->assertEquals('value2', $headers['custom-new']);
}

public function testCanAddHeaders()
Expand Down

0 comments on commit 8f55a8f

Please sign in to comment.