Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Codeception/Module/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ protected function getRunningClient(): AbstractBrowser
return $this->client;
}

/**
* Returns all HTTP headers from the last response.
*
* ```php
* <?php
* $I->sendGet('/message/1');
* $headers = $I->grabHttpHeaders();
* ```
*
* @part json
* @part xml
*/
public function grabHttpHeaders(): array
{
return $this->getRunningClient()->getInternalResponse()->getHeaders();
}

/**
* Sets a HTTP header to be used for all subsequent requests. Use [`unsetHttpHeader`](#unsetHttpHeader) to unset it.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/Codeception/Module/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ public function testUrlIsFull()
$this->assertSame('http://localhost/api/v1/users', $request->getUri());
}

public function testGrabHttpHeaders()
{
$headers = [
'Cache-Control' => ['no-cache', 'no-store'],
'Content_Language' => 'en-US'
];
$response = new SymfonyResponse("", 200, $headers);
$this->module->client->mockResponse($response);
$this->module->sendGET('/');
$this->assertSame($headers, $this->module->grabHttpHeaders());
}

public function testSeeHeaders()
{
$response = new SymfonyResponse("", 200, [
Expand Down