00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Ilya A. Volynets-Evenbakh * 00003 * ilya@total-knowledge.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #ifndef CSERVIMPLSERVLETRESPONSEIMPL_H 00021 #define CSERVIMPLSERVLETRESPONSEIMPL_H 00022 00023 #include <servlet/HttpServletResponse.h> 00024 #include <connection.h> 00025 #include <list> 00026 #include <util.h> 00027 #include <ServletOutputStream.h> 00028 00029 namespace container { 00030 00031 class HttpServletRequestImpl; 00037 class HttpServletResponseImpl : public servlet::HttpServletResponse 00038 { 00039 protected: 00040 HttpServletRequestImpl* m_req; 00041 private: 00042 friend class ServletOutputStreamBuf; 00043 typedef std::list <servlet::Cookie> cookielist_t; 00044 void sendHeaders(Connection& con); 00045 void resetBuffer(); 00046 std::string quoteString(const std::string&); 00047 private: 00048 int m_contentLength; 00049 std::string m_contentType; 00050 std::string m_characterEncoding; 00051 ServletOutputStream m_outputStream; 00052 bool m_committed; 00053 util::mparam_t m_headers; 00054 int m_statusCode; 00055 std::string m_statusMsg; 00056 cookielist_t m_cookies; 00057 00058 public: 00059 HttpServletResponseImpl(Connection& con, const std::string&, const std::string&); 00060 ~HttpServletResponseImpl(); 00061 void setReqRef(HttpServletRequestImpl* req){this->m_req=req;} 00062 std::string getStatusMessage(); 00063 00065 virtual std::string getCharacterEncoding(); 00066 virtual std::string getContentType(); 00067 virtual std::ostream& getOutputStream(); 00068 virtual void setCharacterEncoding(const std::string& charset); 00069 virtual void setContentLength(int len); 00070 virtual void setContentType(const std::string& type); 00071 virtual void setBufferSize(int size); 00072 virtual int getBufferSize(); 00073 virtual void flushBuffer(); 00074 virtual bool isCommitted(); 00075 virtual void reset(); 00076 00078 virtual void addCookie(const servlet::Cookie& cookie); 00079 virtual bool containsHeader(const std::string& name) const ; 00080 virtual std::string encodeURL(const std::string& url); 00081 virtual std::string encodeRedirectURL(const std::string& url); 00082 virtual void sendError(int sc, const std::string& msg); 00083 virtual void sendError(int sc); 00084 virtual void sendRedirect(const std::string& location); 00085 virtual void setDateHeader(const std::string& name, long date); 00086 virtual void addDateHeader(const std::string& name, long date); 00087 virtual void setHeader(const std::string& name, const std::string& value); 00088 virtual void addHeader(const std::string& name, const std::string& value); 00089 virtual void setIntHeader(const std::string& name, int value); 00090 virtual void addIntHeader(const std::string& name, int value); 00091 virtual void setStatus(int sc); 00092 }; 00093 00094 } 00095 00096 #endif