HTTPResponseHeader.java
上传用户:huihesys
上传日期:2007-01-04
资源大小:3877k
文件大小:3k
- /* CVS ID: $Id: HTTPResponseHeader.java,v 1.2 2000/04/06 08:02:02 wastl Exp $ */
- package net.wastl.webmail.standalone;
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import net.wastl.webmail.server.WebMailServer;
- import net.wastl.webmail.debug.ErrorHandler;
- /**
- * HTTPHeader.java
- *
- * Created: Tue Feb 2 15:25:48 1999
- *
- * Copyright (C) 1999-2000 Sebastian Schaffert
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /**
- *
- *
- *
- * @author Sebastian Schaffert
- * @version $Revision: 1.2 $
- */
- public class HTTPResponseHeader {
- private String status;
- private int response_code;
- private String http_version="HTTP/1.1";
- private String response_line;
- private Hashtable headers;
- public HTTPResponseHeader(int response_code,String status) {
- headers=new Hashtable();
- this.response_code=response_code;
- this.status=status;
- response_line=http_version+" "+response_code+" "+status;
- putHeader("Server","JWebMail/"+WebMailServer.VERSION);
- SimpleTimeZone tz=new SimpleTimeZone(0,"GMT");
- SimpleDateFormat df=new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", new Locale("en","UK"));
- df.setTimeZone(tz);
- String now=df.format(new Date());
- String now_plus_5=df.format(new Date(System.currentTimeMillis()+300000));
- putHeader("Date",now);
- putHeader("Expires",now_plus_5);
- putHeader("Pragma","no-cache");
- putHeader("Cache-Control","must-revalidate");
- putHeader("Allow","GET, POST");
- }
- public String getResponseLine() {
- return response_line;
- }
- public void putHeader(String key,String value) {
- headers.remove(key);
- headers.put(key,value);
- }
- public String getHeader(String t) {
- return (String)headers.get(t);
- }
- public void removeHeader(String key) {
- headers.remove(key);
- }
- public Enumeration getHeaderKeys() {
- return headers.keys();
- }
- public String toString() {
- String s=response_line+"rn";
- Enumeration e=headers.keys();
- while(e.hasMoreElements()) {
- String h=(String)e.nextElement();
- s+=h+": "+headers.get(h)+"rn";
- }
- s+="rn";
- return s;
- }
-
- } // HTTPHeader