emptygif
Lingua: Italiano

Tutti i linguaggi e framework

PSGI / Plack Perl

Uno snippet Perl per PSGI / Plack che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

PSGI / Plack Perl

Installa
cpanm Plack
File
app.psgi
Esegui
plackup -p 8080 app.psgi
use strict;
use warnings;
use MIME::Base64 qw(decode_base64);

my $gif = decode_base64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

my $app = sub {
    my $env = shift;
    return [404, ['Content-Type' => 'text/plain'], ['Not Found']]
        unless $env->{REQUEST_METHOD} eq 'GET' && $env->{PATH_INFO} eq '/pixel.gif';
    return [
        200,
        [
            'Content-Type'   => 'image/gif',
            'Content-Length' => length($gif),
            'Cache-Control'  => 'no-store',
        ],
        [$gif],
    ];
};

Abbiamo eseguito questo snippet e confrontato i byte che ha restituito.

Verifica

curl -sI http://localhost:8080/pixel.gif

Sito ufficiale: PSGI / Plack

Altro in Perl