ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/eg/httpd
Revision: 1.1
Committed: Mon Dec 6 19:33:58 2010 UTC (15 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-0_1, rel-0_2, rel-0_9
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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;