use strict; $| = 1; # autoflush require IO::Socket; require HTTP::Daemon; my $handlerScript = shift || die "no handler given"; my $d = HTTP::Daemon->new() || die; print "HTTP Server started at: <", $d->url, ">\n"; open(STDOUT, $^O eq 'VMS'? ">nl: " : ">/dev/null"); print STDERR "HTTP Server started\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r) { if ($r->method eq 'GET' and $r->url->path eq "/quit") { $c->send_error(503, "Bye, bye"); print STDERR "HTTP Server terminated\n"; exit; # terminate HTTP server } else { require $handlerScript; handler($r, $c); } } } $c->close; $c = undef; # close connection }