-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4830831
commit 9229264
Showing
1 changed file
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Illuminate\Http\Middleware; | ||
|
||
use Illuminate\Contracts\Foundation\Application; | ||
use Illuminate\Http\Request; | ||
|
||
abstract class TrustHosts | ||
{ | ||
/** | ||
* The application instance. | ||
* | ||
* @var \Illuminate\Contracts\Foundation\Application | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* Create a new middleware instance. | ||
* | ||
* @param \Illuminate\Contracts\Foundation\Application $app | ||
* @return void | ||
*/ | ||
public function __construct(Application $app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* Get the host patterns that should be trusted. | ||
* | ||
* @return array | ||
*/ | ||
abstract public function hosts(); | ||
|
||
/** | ||
* Handle the incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param callable $next | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function handle(Request $request, $next) | ||
{ | ||
if ($this->shouldSpecifyTrustedHosts()) { | ||
Request::setTrustedHosts(array_filter($this->hosts())); | ||
} | ||
|
||
return $next($request); | ||
} | ||
|
||
/** | ||
* Determine if the application should specify trusted hosts. | ||
* | ||
* @return bool | ||
*/ | ||
protected function shouldSpecifyTrustedHosts() | ||
{ | ||
return config('app.env') !== 'local' && | ||
! $this->app->runningUnitTests(); | ||
} | ||
|
||
/** | ||
* Get a regular expression matching the application URL and all of its subdomains. | ||
* | ||
* @return string|null | ||
*/ | ||
protected function allSubdomainsOfApplicationUrl() | ||
{ | ||
if ($host = parse_url($this->app['config']->get('app.url'), PHP_URL_HOST)) { | ||
return '^(.+\.)?'.preg_quote($host).'$'; | ||
} | ||
} | ||
} |