Monday, November 08, 2010 at 12:06 AM.


on echoResponder (adrParamTable) {
	<<3/3/98 at 9:36:20 PM by WMF
		<<This is a debugging responder that echos all the parameters that are available to a responder 
		<<It is similar to the samples.tellParams CGI
	<<9/26/98; 6:38:48 AM by DW
		<<improved the HTML it generates to make it prettier and to learn how to upgrade responders
	local (htmltext = "", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledString ("\t", indentlevel) + s + "\r"};
	local (title = "Echo Responder for \"" + tcp.dns.getMyDomainName () + "\"");
	add ("<html>"); indentlevel++;
	add ("<head>"); indentlevel++;
	add ("<title>" + title + "</title>");
	add ("</head>"); indentlevel--;
	add ("<body>"); indentlevel++;
	on addTable (adrtable) {
		local (i, adritem, val);
		add ("<table cellpadding=\"2\" border=\"0\">"); indentlevel++;
		add ("<tr>"); indentlevel++;
		add ("<td valign=\"top\"><b>" + "Name" + "</b></td>");
		add ("<td>  </td>");
		add ("<td valign=\"top\"><b>" + "Value" + "</b></td>");
		add ("</tr>"); indentlevel--;
		for i = 1 to sizeof (adrtable^) {
			adritem = @adrtable^ [i];
			if typeof (adritem^) == tabletype {
				val = sizeof (adritem^) + " items"}
			else {
				val = string (adritem^);
				if sizeof (val) == 0 {
					val = "\"\""};
				if val contains "\r" {
					val = "<pre>" + string.trimWhitespace (val) + "</pre>"}};
			add ("<tr>"); indentlevel++;
			add ("<td valign=\"top\">" + nameof (adritem^) + "</td>");
			add ("<td> </td>");
			add ("<td valign=\"top\">" + val + "</td>");
			add ("</tr>"); indentlevel--};
		add ("</table>"); indentlevel--};
	add ("<blockquote>"); indentlevel++;
	add ("<h2>" + title + "</h2>");
	add ("<blockquote>"); indentlevel++;
	bundle { //add introductory text
		add ("This responder shows you the contents of the param table for an HTTP request received on your machine.");
		add ("The first table shows you the top level items, and the second table shows you the contents of the requestHeaders sub-table.");
		add ("This responder was last updated on " + timeModified (this) + ".");
		add ("<p>")};
	add ("<h4>Top level items in adrParamTable^</h4>");
	add ("<blockquote>"); indentlevel++;
	addTable (adrParamTable);
	add ("</blockquote>"); indentlevel--;
	add ("<h4>Contents of the adrParamTable^.requestHeaders sub-table:</h4>");
	add ("<blockquote>"); indentlevel++;
	addTable (@adrParamTable^.requestHeaders);
	add ("</blockquote>"); indentlevel--;
	add ("</blockquote>"); indentlevel--;
	add ("</blockquote>"); indentlevel--;
	add ("</body>"); indentlevel--;
	add ("</html>"); indentlevel--;
	adrParamTable^.responseHeaders.["Content-Type"] = "text/html"; // always set the MIME type
	adrParamTable^.responseBody = htmltext;
	return (true)}
<<bundle //test code
	<<local (params)
	<<new (tabletype, @params)
	<<params.client = tcp.dns.getMyDomainName ()
	<<new (tabletype, @params.requestHeaders)
	<<params.requestHeaders.somevalue = "Hello!"
	<<new (tabletype, @params.responseHeaders)
	<<get (@params)
	<<webbrowser.displaytext (params.responseBody)

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.