HTTPResponseHeader.cpp

00001 /* -*-mode:c++; c-file-style: "gnu";-*- */
00002 /*
00003  *  $Id: HTTPResponseHeader_8cpp-source.html,v 1.1 2007/07/03 21:34:49 sebdiaz Exp $
00004  *
00005  *  Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
00006  *                       2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
00007  *  Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU Lesser General Public
00011  *  License as published by the Free Software Foundation; either
00012  *  version 3 of the License, or (at your option) any later version.
00013  *
00014  *  This library is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  *  Lesser General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU Lesser General Public
00020  *  License along with this library; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 
00022  */
00023 
00024 #ifdef __GNUG__
00025 #  pragma implementation
00026 #endif
00027 
00028 #include "cgicc/HTTPResponseHeader.h"
00029 
00030 // ============================================================
00031 // Class HTTPResponseHeader
00032 // ============================================================
00033 cgicc::HTTPResponseHeader::HTTPResponseHeader(const std::string& version,
00034                                               int status_code,
00035                                               const std::string& reason)
00036   : MStreamable(),
00037     fHTTPVersion(version),
00038     fStatusCode(status_code),
00039     fReasonPhrase(reason)
00040 {
00041   fHeaders.reserve(5);
00042 }
00043 
00044 cgicc::HTTPResponseHeader::~HTTPResponseHeader()
00045 {}
00046 
00047 cgicc::HTTPResponseHeader&
00048 cgicc::HTTPResponseHeader::addHeader(const std::string& header)
00049 {
00050   fHeaders.push_back(header); 
00051   return *this; 
00052 }
00053 
00054 cgicc::HTTPResponseHeader&
00055 cgicc::HTTPResponseHeader::addHeader(const std::string& name,
00056                                      const std::string& value)
00057 { 
00058   fHeaders.push_back(name + ": " + value); 
00059   return *this; 
00060 }
00061 
00062 cgicc::HTTPResponseHeader&
00063 cgicc::HTTPResponseHeader::setCookie(const HTTPCookie& cookie)
00064 { 
00065   fCookies.push_back(cookie); 
00066   return *this; 
00067 }
00068 
00069 void 
00070 cgicc::HTTPResponseHeader::render(std::ostream& out)    const
00071 {
00072   std::vector<std::string>::const_iterator iter;
00073   std::vector<HTTPCookie>::const_iterator cookie_iter; 
00074   
00075   out << fHTTPVersion << ' ' << fStatusCode << ' ' << fReasonPhrase 
00076       << std::endl;
00077   
00078   for(iter = fHeaders.begin(); iter != fHeaders.end(); ++iter)
00079     out << *iter << std::endl;
00080   
00081   for(cookie_iter = getCookies().begin(); 
00082       cookie_iter != getCookies().end(); 
00083       ++cookie_iter)
00084     out << *cookie_iter << std::endl;
00085   
00086   out << std::endl;
00087 }

Generated on Tue Jul 3 15:44:29 2007 for GNUCgicc by  doxygen 1.5.1