require "cgi"
$c = CGI.new()
def htmlContents(page)
%Q{Content-Type: text/html
Content-Length: #{page.length}
#{page}
}
end
def envPart
res = ""
ENV.keys.sort.each do |k|
v = ENV[k]
res << "<tr><th>" << k.to_s \
<< "</th><td>" << CGI.escapeHTML(v.to_s) \
<< "</td></tr>"
end
res = "<table>" + res + "</table>"
res
end
def cgiParams
res = ""
$c.params.keys.each do |k|
v = $c.params[k]
res << "<tr><th>" << k.to_s \
<< "</th><td>" \
<< CGI.escapeHTML(v.to_s) \
<< "</td></tr>"
end
res = "<table>" + res + "</table>"
res
end
def testPage
res = %Q{<html>
<head>
<title>The CGI Components</title>
<style>
th {text-align: left}
</style>
</head>
<body>
<h1>The Environment</h1>
#{envPart}
<h1>The CGI params</h1>
#{cgiParams}
</body>
</html>
}
CGI.pretty(res)
end
$stdout.print(htmlContents(testPage))