-
-
Save takus/621ab1892d96233a882a4b29fed0a6cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM perl:latest | |
RUN cpanm install Starlet | |
ADD oversleep.psgi /oversleep.psgi | |
EXPOSE 5000 | |
CMD ["plackup", "-p", "5000", "-s", "Starlet", "--max-workers=8", "/oversleep.psgi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: cperl; -*- | |
use Plack::Request; | |
my $app = sub { | |
my $env = shift; | |
my $req = Plack::Request->new($env); | |
my $path_info = $req->path_info; | |
if ( $path_info eq "/ping" ) { | |
if ( -f "/maintenance" ) { | |
return [ | |
599, | |
[ 'Content-Type' => 'text/plain' ], | |
[ "MAINTENANCE\n" ] | |
]; | |
} | |
return [ | |
200, | |
[ 'Content-Type' => 'text/plain' ], | |
[ "OK\n" ] | |
]; | |
} | |
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