Initial Commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ImageProxyController extends Controller
|
||||
{
|
||||
public function show(Request $request)
|
||||
{
|
||||
$request->validate(['url' => 'required|url']);
|
||||
|
||||
$url = $request->query('url');
|
||||
|
||||
// Only allow proxying Instagram's own CDN domains, so this
|
||||
// can't be abused as an open proxy for arbitrary URLs.
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if (! $host || ! str_ends_with($host, 'fbcdn.net') && ! str_ends_with($host, 'cdninstagram.com')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'User-Agent' => 'Mozilla/5.0',
|
||||
])->get($url);
|
||||
|
||||
if (! $response->successful()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response($response->body())
|
||||
->header('Content-Type', $response->header('Content-Type'))
|
||||
->header('Cache-Control', 'public, max-age=3600');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user