Skip to content

Commit

Permalink
Merge pull request #87 from koriym/header
Browse files Browse the repository at this point in the history
rendering before any output in HttpResponder
  • Loading branch information
koriym committed Aug 24, 2015
2 parents 85ddb89 + 8693d8b commit 0a28331
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Provide/Transfer/HttpResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class HttpResponder implements TransferInterface
*/
public function __invoke(ResourceObject $resourceObject, array $server)
{
// render
$body = (string) $resourceObject;

// code
http_response_code($resourceObject->code);

Expand All @@ -25,6 +28,6 @@ public function __invoke(ResourceObject $resourceObject, array $server)
}

// body
echo (string) $resourceObject;
echo $body;
}
}
5 changes: 4 additions & 1 deletion tests/Provide/Transfer/HttpResponderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public function testTransfer()
{
$ro = (new FakeResource)->onGet();
$ro->transfer($this->responder, []);
$expectedArgs = [['Cache-Control: max-age=0', false]];
$expectedArgs = [
['Cache-Control: max-age=0', false],
['content-type: application/json', false],
];
$this->assertEquals($expectedArgs, FakeHttpResponder::$headers);
$expect = '{"greeting":"hello world"}';
$actual = FakeHttpResponder::$content;
Expand Down

0 comments on commit 0a28331

Please sign in to comment.