implement echo; include "sys.m"; sys : Sys; stderr : ref Sys->FD; include "bufio.m"; Iobuf : import Bufio; include "draw.m"; draw : Draw; include "content.m"; Content : import Cont; include "cache.m"; include "httpd.m"; include "cgiparse.m"; cgiparse : CgiParse; echo : module { init : fn( g : ref Private_info, argv: list of string); }; init( g : ref Private_info, argv: list of string ) { sys = load Sys "$Sys"; draw = load Draw "$Draw"; stderr = sys->fildes(2); cgiparse = load CgiParse CgiParse->PATH; if( cgiparse == nil ){ sys->fprint( stderr, "Echo load CgiParse: %r\n" ); return; } cgidata := cgiparse->cgipar( g, argv ); send( g, cgidata ); return; } send( g : ref Private_info, cgidata : ref CgiData ) { k := g.bufmod; Iobuf : import k; if( cgidata == nil ){ g.bout.flush(); return; } g.bout.puts( cgidata.httphd ); g.bout.puts("Echo\r\n"); g.bout.puts("

Echo

\r\n"); g.bout.puts(sys->sprint("You requested a %s on %s", cgidata.method, cgidata.uri)); if(cgidata.search!=nil) g.bout.puts(sys->sprint(" with search string %s", cgidata.search)); g.bout.puts(".\n"); g.bout.puts("Your client sent the following headers:

");
    g.bout.puts( "Client: " + cgidata.remote + "\n" );
    g.bout.puts( "Date: " + cgidata.tmstamp + "\n" );
    g.bout.puts( "Version: " + cgidata.version + "\n" );
    while( cgidata.header != nil ){
	(tag, val) := hd cgidata.header;
	g.bout.puts( tag + " " + val + "\n" );
	cgidata.header = tl cgidata.header;
    }

    g.bout.puts("
\n"); if (cgidata.method=="POST"){ i := 0; g.bout.puts(""); g.bout.puts("Your client sent the following form data:

"); g.bout.puts("\n"); while(cgidata.form!=nil){ (tag, val) := hd cgidata.form; g.bout.puts(sys->sprint(" "); g.bout.puts("\n"); g.bout.puts("\n"); cgidata.form = tl cgidata.form; i++; } g.bout.puts("
%d ",i)); g.bout.puts(tag); g.bout.puts(" "); g.bout.puts(val); g.bout.puts("
\n"); } g.bout.puts("\n"); g.bout.flush(); return; }