01: /* $Id: HTTPResponseHeader.java,v 1.1.1.1 2002/10/02 18:42:53 wastl Exp $ */
02: package net.wastl.webmail.server.http;
03:
04: import java.io.*;
05: import java.util.*;
06: import java.text.*;
07: import net.wastl.webmail.server.WebMailServer;
08: import net.wastl.webmail.debug.ErrorHandler;
09: import net.wastl.webmail.exceptions.*;
10:
11: /**
12: * HTTPHeader.java
13: *
14: *
15: * Created: Tue Feb 2 15:25:48 1999
16: *
17: * @author Sebastian Schaffert
18: * @version $Revision: 1.1.1.1 $
19: */
20:
21: public class HTTPResponseHeader {
22:
23: private String status;
24: private int response_code;
25: private String http_version = "HTTP/1.1";
26:
27: private String response_line;
28:
29: private Hashtable headers;
30:
31: public HTTPResponseHeader(int response_code, String status) {
32: headers = new Hashtable();
33: this .response_code = response_code;
34: this .status = status;
35:
36: response_line = http_version + " " + response_code + " "
37: + status;
38:
39: putHeader("Server", "JWebMail/" + WebMailServer.VERSION);
40: SimpleTimeZone tz = new SimpleTimeZone(0, "GMT");
41: SimpleDateFormat df = new SimpleDateFormat(
42: "EEE, dd MMM yyyy HH:mm:ss z", new Locale("en", "UK"));
43: df.setTimeZone(tz);
44: String now = df.format(new Date());
45: String now_plus_5 = df.format(new Date(System
46: .currentTimeMillis() + 300000));
47: putHeader("Date", now);
48: putHeader("Expires", now_plus_5);
49: putHeader("Pragma", "no-cache");
50: putHeader("Cache-Control", "must-revalidate");
51: putHeader("Allow", "GET, POST");
52: }
53:
54: public String getResponseLine() {
55: return response_line;
56: }
57:
58: public void putHeader(String key, String value) {
59: headers.remove(key);
60: headers.put(key, value);
61: }
62:
63: public String getHeader(String t) {
64: return (String) headers.get(t);
65: }
66:
67: public void removeHeader(String key) {
68: headers.remove(key);
69: }
70:
71: public Enumeration getHeaderKeys() {
72: return headers.keys();
73: }
74:
75: public String toString() {
76: String s = response_line + "\r\n";
77: Enumeration e = headers.keys();
78: while (e.hasMoreElements()) {
79: String h = (String) e.nextElement();
80: s += h + ": " + headers.get(h) + "\r\n";
81: }
82: s += "\r\n";
83: return s;
84: }
85:
86: } // HTTPHeader
|