Actually set the HTTP status code...
[jsvc.git] / src / dolda / jsvc / test / TestResponder.java
1 package dolda.jsvc.test;
2
3 import dolda.jsvc.*;
4 import dolda.jsvc.util.*;
5 import java.io.*;
6
7 public class TestResponder implements Responder {
8     public void respond(Request req) {
9         req.outheaders().put("Content-Type", "text/html; charset=utf-8");
10         PrintWriter out;
11         try {
12             out = new PrintWriter(new OutputStreamWriter(req.output(), "UTF-8"));
13         } catch(UnsupportedEncodingException e) {
14             throw(new Error(e));
15         }
16
17         if(req.path().equals("bard1"))
18             throw(new RuntimeException("bard1"));
19
20         out.println("<html>");
21         out.println("<head><title>Barda</title></head>");
22         out.println("<body>");
23         out.println("<h1>Barda</h1>");
24         out.println("Bardslen.");
25         out.println(req.inheaders());
26         out.println(req.ctx().starttime());
27         out.println(req.remoteaddr() + "<->" + req.localaddr());
28         out.println("</body>");
29         out.println("</html>");
30
31         if(req.path().equals("bard2"))
32             throw(Restarts.redirectctx("/slen"));
33         out.flush();
34     }
35 }