11 perl -Ilib/PXElator -Mhttpd -e httpd::start
15 use Data::Dump qw/dump/;
26 our $url = "http://$server::ip:$port/";
31 my ($client,$path) = @_;
35 if ( ! -e $path || -d $path ) {
36 print $client "HTTP/1.0 404 $path not found\r\n";
40 my $type = 'text/plain';
41 $type = 'text/html' if $path =~ m{\.htm};
42 $type = 'application/javascript' if $path =~ m{\.js};
44 print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: ", -s $path,"\r\n\r\n";
45 open(my $html, $path);
54 my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";
59 my ( $client, $path, $param ) = @_;
61 warn "get_request $client $path $param";
63 if ( my $found = static( $client,$path ) ) {
64 warn "static $found" if $debug;
65 } elsif ( $path eq '/' ) {
69 'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,
72 } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
73 eval 'our $' . $1 . ' = ' . $2;
75 print $client qq|HTTP/1.1 302 Found\r\nLocation: $url\r\nContent-type: text/html\r\n\r\n<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;
76 } elsif ( $path =~ m{/boot} ) {
81 chain http://$server::ip:$httpd::port/
85 print $client "HTTP/1.0 404 $path\r\nConnection: close\r\nContent-type: text/html\r\n\r\n<big>404 $path</big>";
92 my $server = IO::Socket::INET->new(
94 LocalPort => $httpd::port,
97 ) || die "can't start server on $url: $!";
101 system "/mnt/llin/rest/cvs/uzbl/uzbl -u $url &";
103 while (my $client = $server->accept()) {
104 $client->autoflush(1);
105 my $request = <$client>;
107 warn "request $request\n" if $debug;
109 Module::Refresh->refresh;
111 if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {
114 if ( $path =~ s{\?(.+)}{} ) {
115 foreach my $p ( split(/[&;]/, $1) ) {
116 my ($n,$v) = split(/=/, $p, 2);
119 warn "param: ",dump( $param ) if $debug;
121 warn "path $path param: ",dump( $param );
122 get_request $client, $path, $param;
124 print $client "HTTP/1.0 500 No method\r\nConnection: close\r\nContent-type: text/plain\r\n\r\n500 $request";
129 <div style="font-size: 80%; color: #888">
130 <a href="">reload</a>
131 <a href="/">index</a>
133 } if $client->connected;