emptygif
Idioma: Português

Todas as linguagens e frameworks

PSGI / Plack Perl

Um snippet em Perl para PSGI / Plack que responde às requisições para /pixel.gif com o GIF vazio, decodificado uma única vez na inicialização.

PSGI / Plack Perl

Instalar
cpanm Plack
Arquivo
app.psgi
Executar
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],
    ];
};

Executamos este snippet e comparamos os bytes que ele retornou.

Verificar

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

Site oficial: PSGI / Plack

Mais em Perl