emptygif
语言: 简体中文

所有语言和框架

PSGI / Plack Perl

一个用于 PSGI / Plack 的 Perl 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

PSGI / Plack Perl

安装
cpanm Plack
文件
app.psgi
运行
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],
    ];
};

我们运行了此代码片段,并比对了它返回的字节。

验证

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

官方网站: PSGI / Plack

更多 Perl 示例