Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uzegonemad/f30375bd4feebd42e719 to your computer and use it in GitHub Desktop.
Save uzegonemad/f30375bd4feebd42e719 to your computer and use it in GitHub Desktop.
Laravel 5 Middleware - Strip X-Requested-For Header
<?php namespace App\Http\Middleware;
use Closure;
class StripHeaders {
/**
* Strip X-Requested-With from the request because we're handling
* all json output and don't want interference from Laravel.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Remove from ServerBag / ParameterBag
$request->server->remove('HTTP_X_REQUESTED_WITH');
// Remove from HeaderBag
$request->headers->remove('x-requested-with');
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment