Skip to content

Instantly share code, notes, and snippets.

@jbrooksuk
Created August 8, 2019 12:34
Show Gist options
  • Save jbrooksuk/4eeb5adba6b786689ac91b39c880e0ad to your computer and use it in GitHub Desktop.
Save jbrooksuk/4eeb5adba6b786689ac91b39c880e0ad to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
class ClientHint
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if (strpos($request->header('accept'), 'image/webp')) {
$defaults = Config::get('images.defaults');
Config::set('images.defaults', array_merge($defaults, [
'fm' => 'webp',
]));
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment