Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 36025de9bf
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 38 lines (33 sloc) 0.983 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/local/bin/perl6
use HTTP::Daemon;
use Web::Nibbler;

# Serve one page
sub request($c) {
    my $r = $c.get_request;
    if $r.req_method eq 'GET' {
        # log request info to the standard error stream
        warn "{hhmm} GET {$r.url.path} {$r.header('User-Agent')}";
        my $qs = $r.url.path ~~ / '?' (.*) $/
                    ?? $0
                    !! '';
        $c.send_response(
            ~([~] Web::Nibbler.call({"QUERY_STRING" => $qs}).[2])
        );
    }
    else {
        warn "{hhmm} rejected {$r.req_method} {$r.url.path}";
        $c.send_error('RC_FORBIDDEN');
    }
    warn ' '; # blank line
}

# give the current time in hh:mm format
sub hhmm {
    my $t = int(time);
    my $m = int( $t / 60 ) % 60;
    my $h = int( $t / 3600 ) % 24;
    my $hhmm = "{$h.fmt('%02d')}:{$m.fmt('%02d')}";
    return $hhmm;
}

my HTTP::Daemon $d .= new( host=> '127.0.0.1', port=> 8888 );
say "Browse this Perl 6 (Rakudo) web server at {$d.url}";
$d.daemon();

Something went wrong with that request. Please try again.