diff src/goodjava/webserver/examples/Params.java @ 1402:27efb1fcbcb5

move luan.lib to goodjava
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 17 Sep 2019 01:35:01 -0400
parents src/luan/lib/webserver/examples/Params.java@643cf1c37723
children fa066aaa068c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/goodjava/webserver/examples/Params.java	Tue Sep 17 01:35:01 2019 -0400
@@ -0,0 +1,30 @@
+package goodjava.webserver.examples;
+
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.io.IOException;
+import java.util.Map;
+import goodjava.webserver.Handler;
+import goodjava.webserver.Request;
+import goodjava.webserver.Response;
+import goodjava.webserver.ResponseOutputStream;
+
+
+public final class Params implements Handler {
+
+	public Response handle(Request request) {
+		Response response = new Response();
+		response.headers.put( "content-type", "text/plain; charset=utf-8" );
+		try {
+			Writer writer = new OutputStreamWriter( new ResponseOutputStream(response) );
+			for( Map.Entry<String,Object> entry : request.parameters.entrySet() ) {
+				writer.write(entry.getKey()+" = "+entry.getValue()+"\n");
+			}
+			writer.close();
+		} catch(IOException e) {
+			throw new RuntimeException(e);
+		}
+		return response;
+	}
+
+}