Mercurial Hosting > luan
annotate src/goodjava/webserver/examples/Headers.java @ 1703:3a61451f8130
add bbcode video
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 Jul 2022 00:12:05 -0600 |
parents | fa066aaa068c |
children |
rev | line source |
---|---|
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
1 package goodjava.webserver.examples; |
1141
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 import java.io.Writer; |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 import java.io.OutputStreamWriter; |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 import java.io.IOException; |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 import java.util.Map; |
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
7 import goodjava.webserver.Handler; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
8 import goodjava.webserver.Request; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
9 import goodjava.webserver.Response; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
10 import goodjava.webserver.ResponseOutputStream; |
1141
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 public final class Headers implements Handler { |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 public Response handle(Request request) { |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 Response response = new Response(); |
1607 | 17 response.headers.put( "Content-Type", "text/plain; charset=utf-8" ); |
1141
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 try { |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 Writer writer = new OutputStreamWriter( new ResponseOutputStream(response) ); |
1146
2dda3c92a473
webserver - implement cookies
Franklin Schmidt <fschmidt@gmail.com>
parents:
1141
diff
changeset
|
20 for( Map.Entry<String,Object> entry : request.headers.entrySet() ) { |
1141
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 writer.write(entry.getKey()+": "+entry.getValue()+"\n"); |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 } |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 writer.close(); |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 } catch(IOException e) { |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 throw new RuntimeException(e); |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 } |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 return response; |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 } |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
14927c34cbb7
webserver - add examples/Headers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 } |