implement Handler;
include "sys.m";
sys: Sys;
include "bufio.m";
include "http.m";
http: Http;
HConn: import http;
headers: Headers;
HeaderMap: import headers;
msgs := array[] of {
("html", "
:(:(
Your PC ran into a problem and needs to restart."),
("html", "This is a test of the Emergency Broadcast System.
" +
"The Internet service providers in your area, "+
"in voluntary cooperation with the FCC " +
"and federal, state, and local authorities, " +
"have developed this system to keep you informed " +
"in the event of an emergency."),
("html", "Problem loading page" +
"This address is restricted
" +
"This address uses a network port which is normally used for purposes " +
"other than Web browsing. Firefox has canceled the request for your protection."),
("plain", "A problem has been detected and windows has been shut down " +
"to prevent damage to your computer."),
("plain", "An unfortunate error has occured."),
("plain", "Error establishing a database connection"),
("plain", "bad low epoch (must be <= 18629)"),
("plain", "swapon: /dev/disk/by-uuid/928aaabd-5744-4f0a-b9ef-aa101f286514: Invalid argument"),
("plain", "venti i/o error block 0x7d97e98f8af710c7e7fe703abc8f639e0ee507c4"),
};
init(m: Http, args: list of string)
{
sys = load Sys Sys->PATH;
http = m;
headers = http->headers;
if(len args > 1) {
sys->fprint(sys->fildes(2), "usage: %s\n", hd args);
raise "fail:usage";
}
}
handle(h: ref HConn)
{
i := (sys->millisec() >> 20) % len msgs; # change every 17 minutes
(t, s) := msgs[i];
h.status(500, nil);
h.rsp.hmap.add("Content-Type", "text/" + t);
if(t == "html")
h.puts("\n");
h.puts(s + "\n");
if(t == "html")
h.puts("\n");
}