| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
use AnyEvent::HTTPD; |
| 4 |
|
|
|
| 5 |
|
|
my $httpd = AnyEvent::HTTPD->new (port => 9090); |
| 6 |
|
|
|
| 7 |
|
|
warn "AnyEvent::HTTPD listening on: http://localhost:9090/\n"; |
| 8 |
|
|
|
| 9 |
|
|
$httpd->reg_cb ( |
| 10 |
|
|
'/' => sub { |
| 11 |
|
|
my ($httpd, $req) = @_; |
| 12 |
|
|
|
| 13 |
|
|
$req->respond ([200 => "OK", { 'Content-Type' => 'text/html' }, |
| 14 |
|
|
"<html><body><h1>files embedded in this staticperl</h1>" |
| 15 |
|
|
. (join "", map "<a href=\"$_\">$_</a><br />", sort +static::list) |
| 16 |
|
|
. "</body></html>" |
| 17 |
|
|
]); |
| 18 |
|
|
}, |
| 19 |
|
|
'' => sub { |
| 20 |
|
|
my ($httpd, $req) = @_; |
| 21 |
|
|
|
| 22 |
|
|
my $file = static::find substr $req->url, 1; |
| 23 |
|
|
$req->respond ([200 => "OK", { 'Content-Type' => 'text/plain; charset=utf-8' }, $file]); |
| 24 |
|
|
}, |
| 25 |
|
|
); |
| 26 |
|
|
|
| 27 |
|
|
$httpd->run; |