Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- mode: cperl; -*-
use Plack::Request;
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
if ((my $t = $req->param("t")) > 0) {
sleep $t;
return [
200,
[ 'Content-Type' => 'text/plain' ],
[ "slept $t\n" ]
];
} elsif ((my $t = $req->param("b")) > 0) {
return sub {
my $respond = shift;
my $writer = $respond->([ 200, ['Content-Type'=>'text/plain'] ]);
sleep $t;
$writer->write("write header and slept $t\n");
};
} elsif ($req->param("d")) {
return sub {
my $respond = shift;
my $writer = $respond->([ 200, ['Content-Type'=>'text/plain'] ]);
for (my $i=1; $i<7; $i++) {
$writer->write("delayed $i\n");
sleep 2;
}
};
} else {
return [
200,
[ 'Content-Type' => 'text/plain' ],
[ "quick\n" ]
];
}
};
__END__
plackup -p 5000 -s Starlet --max-workers=8 oversleep.psgi
query_string:
r=1 : すぐレスポンス返す。(デフォルト)
t=T : T秒(T>1)寝てヘッダとレスポンス返す。
b=T : ヘッダを返してからT秒(T>1)寝てレスポンス返す。
d=1 : 遅延レスポンスを返す。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.