Skip to content

Commit

Permalink
the header must be in response
Browse files Browse the repository at this point in the history
  • Loading branch information
kpicaza committed Jun 5, 2021
1 parent 7f6ed5f commit f3fd882
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/NoFLoCMiddleware.php
Expand Up @@ -13,8 +13,10 @@ final class NoFLoCMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$request = $request->withHeader('Permission-Policy', 'interest-cohort=()');
$response = $handler->handle($request);

return $handler->handle($request);
$response->withAddedHeader('Permission-Policy', 'interest-cohort=()');

return $response;
}
}
12 changes: 9 additions & 3 deletions test/NoFLoCMiddlewareTest.php
Expand Up @@ -6,6 +6,7 @@

use Antidot\NoFLoC\NoFLoCMiddleware;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

Expand All @@ -15,10 +16,15 @@ public function testItShouldSetPermissionsPolicyHeaderAsInterestCohort(): void
{
$handler = $this->createMock(RequestHandlerInterface::class);
$request = $this->createMock(ServerRequestInterface::class);
$request->expects($this->once())
->method('withHeader')
$response = $this->createMock(ResponseInterface::class);
$handler->expects(self::once())
->method('handle')
->with($request)
->willReturn($response);
$response->expects(self::once())
->method('withAddedHeader')
->with('Permission-Policy', 'interest-cohort=()')
->willReturn($request);
->willReturn($response);

$middleware = new NoFLoCMiddleware();
$middleware->process($request, $handler);
Expand Down

0 comments on commit f3fd882

Please sign in to comment.