Mercurial Hosting > luan
view src/goodjava/webserver/examples/Headers.java @ 1408:5b8f76e26ab7
remove old backups
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 24 Sep 2019 15:02:33 -0600 |
parents | 27efb1fcbcb5 |
children | fa066aaa068c |
line wrap: on
line source
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 Headers 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.headers.entrySet() ) { writer.write(entry.getKey()+": "+entry.getValue()+"\n"); } writer.close(); } catch(IOException e) { throw new RuntimeException(e); } return response; } }