அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்
Swoole PHP
/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், Swoole க்கான PHP ஸ்னிப்பெட். GIF ஸ்டார்ட்அப்பில் ஒருமுறை மட்டுமே டீகோட் செய்யப்படுகிறது.
Swoole PHP
<?php
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;
$gif = base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
$server = new Server('0.0.0.0', 8080);
$server->set(['http_compression' => false]); // gzip only makes a tiny GIF bigger
$server->on('request', function (Request $request, Response $response) use ($gif) {
if ($request->server['request_uri'] !== '/pixel.gif') {
$response->status(404);
$response->end();
return;
}
$response->header('Content-Type', 'image/gif');
$response->header('Cache-Control', 'no-store');
$response->end($gif);
});
$server->start();
இந்த ஸ்னிப்பெட்டை ரன் செய்து, அது திருப்பித் தந்த பைட்களை ஒப்பிட்டுப் பார்த்தோம்.
சரிபார்
curl -sI http://localhost:8080/pixel.gif