-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ARCANEDEV/patch-1
Updating the middleware
- Loading branch information
Showing
3 changed files
with
22 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php namespace Arcanedev\SpamBlocker\Middleware; | ||
<?php namespace Arcanedev\SpamBlocker\Http\Middleware; | ||
|
||
use Arcanedev\SpamBlocker\Contracts\SpamBlocker; | ||
use Closure; | ||
|
@@ -7,7 +7,7 @@ | |
/** | ||
* Class BlockReferralSpam | ||
* | ||
* @package Arcanedev\LaravelReferralSpamBlocker\Middleware | ||
* @package Arcanedev\SpamBlocker\Http\Middleware | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class BlockReferralSpam | ||
|
@@ -18,7 +18,7 @@ class BlockReferralSpam | |
*/ | ||
|
||
/** @var \Arcanedev\SpamBlocker\Contracts\SpamBlocker */ | ||
private $blocker; | ||
protected $blocker; | ||
|
||
/* ----------------------------------------------------------------- | ||
| Constructor | ||
|
@@ -53,7 +53,22 @@ public function handle(Request $request, Closure $next) | |
$referer = $request->headers->get('referer'); | ||
|
||
return $this->blocker->isBlocked($referer) | ||
? response('Unauthorized.', 401) | ||
? $this->getBlockedResponse() | ||
: $next($request); | ||
} | ||
|
||
/* ----------------------------------------------------------------- | ||
| Other Methods | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Get the blocked referer's response. | ||
* | ||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response | ||
*/ | ||
protected function getBlockedResponse() | ||
{ | ||
return response('Unauthorized.', 401); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
tests/Middleware/BlockReferralSpamTest.php → ...Http/Middleware/BlockReferralSpamTest.php
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?php namespace Arcanedev\SpamBlocker\Tests\Middleware; | ||
<?php namespace Arcanedev\SpamBlocker\Tests\Http\Middleware; | ||
|
||
use Arcanedev\SpamBlocker\Tests\TestCase; | ||
|
||
/** | ||
* Class BlockReferralSpamTest | ||
* | ||
* @package Arcanedev\SpamBlocker\Tests\Middleware | ||
* @package Arcanedev\SpamBlocker\Tests\Http\Middleware | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class BlockReferralSpamTest extends TestCase | ||
|
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