Todos los lenguajes y frameworks
Symfony PHP
Un fragmento en PHP para Symfony que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.
Symfony PHP
<?php
// src/Controller/PixelController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class PixelController
{
private const GIF_BASE64 = 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
#[Route('/pixel.gif', name: 'pixel', methods: ['GET'])]
public function __invoke(): Response
{
$gif = base64_decode(self::GIF_BASE64);
return new Response($gif, Response::HTTP_OK, [
'Content-Type' => 'image/gif',
'Content-Length' => strlen($gif),
'Cache-Control' => 'no-store',
]);
}
}
Ejecutamos este fragmento y comparamos los bytes que devolvió.
Comprobar
curl -sI http://localhost:8080/pixel.gif