emptygif
Wika: Filipino

Lahat ng language at framework

PSGI / Plack Perl

Isang Perl snippet para sa PSGI / Plack na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

PSGI / Plack Perl

I-install
cpanm Plack
File
app.psgi
Patakbuhin
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],
    ];
};

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: PSGI / Plack

Iba pa sa Perl