-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UncacheableByVarnish middleware (#3)
[ci skip] [skip ci]
- Loading branch information
1 parent
f1077ab
commit 85b1792
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace RichanFongdasen\Varnishable\Middleware; | ||
|
||
use Closure; | ||
|
||
class UncacheableByVarnish | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
$response = $next($request); | ||
|
||
\Varnishable::addUncacheableHeader($response); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace RichanFongdasen\Varnishable\Tests\Middleware; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use RichanFongdasen\Varnishable\Middleware\UncacheableByVarnish; | ||
use RichanFongdasen\Varnishable\Tests\TestCase; | ||
|
||
class UncacheableByVarnishTests extends TestCase | ||
{ | ||
/** | ||
* Cacheable by varnish middleware object. | ||
* | ||
* @var \RichanFongdasen\Varnishable\Middleware\UncacheableByVarnish | ||
*/ | ||
protected $middleware; | ||
|
||
/** | ||
* Setup the test environment | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->middleware = new UncacheableByVarnish; | ||
} | ||
|
||
/** @test */ | ||
public function it_can_handle_the_incoming_request_and_manipulate_the_response_headers() | ||
{ | ||
$request = new Request; | ||
$response = new Response; | ||
|
||
$this->middleware->handle( | ||
$request, | ||
function (Request $request) use ($response) { return $response; } | ||
); | ||
|
||
$actual = $response->headers->get(\Varnishable::getConfig('uncacheable_header')); | ||
$this->assertEquals('1', $actual); | ||
} | ||
} |