emptygif
언어: 한국어

모든 언어 및 프레임워크

PSGI / Plack Perl

/pixel.gif 요청에 빈 GIF로 응답하는 PSGI / Plack용 Perl 스니펫입니다. 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의 다른 예제