Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3767624
TrustProxy.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
TrustProxy.php
View Options
<?php
namespace
AuthGrove\Http\Middleware
;
use
Illuminate\Http\Request
;
use
AuthGrove\Enums\TrustProxyConfigurationMode
;
use
Config
;
use
Closure
;
/**
* Allow the application to work behind a load balancer or a reverse proxy
*
* See http://symfony.com/doc/current/cookbook/request/load_balancer_reverse_proxy.html
*/
class
TrustProxy
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public
function
handle
(
Request
$request
,
Closure
$next
)
{
$proxy
=
Config
::
get
(
'app.proxy'
);
switch
(
$mode
=
self
::
getConfigurationMode
(
$proxy
))
{
case
TrustProxyConfigurationMode
::
TRUST_NONE
:
break
;
case
TrustProxyConfigurationMode
::
TRUST_SOME
:
$request
->
setTrustedProxies
(
$proxy
);
break
;
case
TrustProxyConfigurationMode
::
TRUST_ALL
:
$remoteAddr
=
$request
->
server
->
get
(
'REMOTE_ADDR'
);
$request
->
setTrustedProxies
([
'127.0.0.1'
,
$remoteAddr
]);
break
;
default
:
throw
new
\ArgumentException
(
"Unhandled configuration mode: $mode"
);
}
return
$next
(
$request
);
}
/**
* Gets trust proxies configuration mode
*/
public
static
function
getConfigurationMode
(
$configValue
)
{
if
(!
is_array
(
$configValue
)
||
!
count
(
$configValue
))
{
return
TrustProxyConfigurationMode
::
TRUST_NONE
;
}
if
(
in_array
(
'*'
,
$configValue
))
{
return
TrustProxyConfigurationMode
::
TRUST_ALL
;
}
return
TrustProxyConfigurationMode
::
TRUST_SOME
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 25, 02:13 (20 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259367
Default Alt Text
TrustProxy.php (1 KB)
Attached To
Mode
rGROVE Auth Grove
Attached
Detach File
Event Timeline
Log In to Comment