Skip to content

Instantly share code, notes, and snippets.

@gabrielkoerich
Created January 18, 2017 01:00
Show Gist options
  • Save gabrielkoerich/b7532a31c3894e2de9e55a3f54681fd4 to your computer and use it in GitHub Desktop.
Save gabrielkoerich/b7532a31c3894e2de9e55a3f54681fd4 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use App;
use Closure;
class ConfigureCloudFlare
{
/**
* Set the CloudFlare conneting IP and https if applied.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! App::environment('production')) {
return $next($request);
}
if ($request->server->has('HTTP_CF_CONNECTING_IP')) {
if ($request->isSecure()) {
$request->server->set('HTTPS', true);
}
$request->server->set('REMOTE_ADDR', $request->server->get('HTTP_CF_CONNECTING_IP'));
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment