HTTPResponseHeader.h
Go to the documentation of this file.
1/* -*-mode:c++; c-file-style: "gnu";-*- */
2/*
3 * $Id: HTTPResponseHeader.h,v 1.10 2014/04/23 20:55:09 sebdiaz Exp $
4 *
5 * Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
6 * 2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
7 * Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 3 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22 */
23
24#ifndef _HTTPRESPONSEHEADER_H_
25#define _HTTPRESPONSEHEADER_H_ 1
26
27#ifdef __GNUG__
28# pragma interface
29#endif
30
38#include <string>
39#include <vector>
40
41#include "MStreamable.h"
42#include "HTTPCookie.h"
43
44 namespace cgicc {
45
46 // ============================================================
47 // Class HTTPResponseHeader
48 // ============================================================
73 class CGICC_API HTTPResponseHeader : public MStreamable
74 {
75 public:
76
79
86 HTTPResponseHeader(const std::string& http_version,
87 int status_code,
88 const std::string& reason_phrase);
89
94 virtual ~HTTPResponseHeader();
96
97 // ============================================================
98
101
108 HTTPResponseHeader&
109 addHeader(const std::string& header);
110
118 HTTPResponseHeader&
119 addHeader(const std::string& name,
120 const std::string& value);
121
127 inline const std::vector<std::string>&
128 getHeaders() const
129 { return fHeaders; }
131
134
139 HTTPResponseHeader&
140 setCookie(const HTTPCookie& cookie);
141
146 inline const std::vector<HTTPCookie>&
147 getCookies() const
148 { return fCookies; }
150
151 // ============================================================
152
157
164 inline const std::string&
165 getHTTPVersion() const
166 { return fHTTPVersion; }
167
174 inline int
175 getStatusCode() const
176 { return fStatusCode; }
177
184 inline std::string
185 getReasonPhrase() const
186 { return fReasonPhrase; }
188
189 // ============================================================
190
195
203 inline HTTPResponseHeader&
204 getHTTPVersion(const std::string& http_version)
205 { fHTTPVersion = http_version; return *this; }
206
214 inline HTTPResponseHeader&
215 getStatusCode(int status_code)
216 { fStatusCode = status_code; return *this; }
217
225 inline HTTPResponseHeader&
226 getReasonPhrase(const std::string& reason_phrase)
227 { fReasonPhrase = reason_phrase; return *this; }
229
230 // ============================================================
231
234 virtual void
235 render(std::ostream& out) const;
237
238 private:
239 HTTPResponseHeader();
240
241 std::string fHTTPVersion;
242 int fStatusCode;
243 std::string fReasonPhrase;
244 std::vector<std::string> fHeaders;
245 std::vector<HTTPCookie> fCookies;
246 };
247
248} // namespace cgicc
249
250#endif /* ! _HTTPRESPONSEHEADER_H_ */
HTTPCookie.h
An HTTP Cookie.
MStreamable.h
Abstract base class for all streamable objects.
cgicc::HTTPCookie
An HTTP cookie.
Definition: HTTPCookie.h:59
cgicc::HTTPResponseHeader
Generic HTTP response header.
Definition: HTTPResponseHeader.h:74
cgicc::HTTPResponseHeader::getHTTPVersion
const std::string & getHTTPVersion() const
Get the HTTP version.
Definition: HTTPResponseHeader.h:165
cgicc::HTTPResponseHeader::getStatusCode
HTTPResponseHeader & getStatusCode(int status_code)
Get the 3-digit status code.
Definition: HTTPResponseHeader.h:215
cgicc::HTTPResponseHeader::addHeader
HTTPResponseHeader & addHeader(const std::string &header)
Add a general, response, or entity header to this one.
cgicc::HTTPResponseHeader::getHTTPVersion
HTTPResponseHeader & getHTTPVersion(const std::string &http_version)
Set the HTTP version.
Definition: HTTPResponseHeader.h:204
cgicc::HTTPResponseHeader::getStatusCode
int getStatusCode() const
Get the 3-digit status code.
Definition: HTTPResponseHeader.h:175
cgicc::HTTPResponseHeader::render
virtual void render(std::ostream &out) const
Write this object to a stream.
cgicc::HTTPResponseHeader::getReasonPhrase
std::string getReasonPhrase() const
Get the reason phrase associated with the stats code.
Definition: HTTPResponseHeader.h:185
cgicc::HTTPResponseHeader::HTTPResponseHeader
HTTPResponseHeader(const std::string &http_version, int status_code, const std::string &reason_phrase)
Create a new HTTP response header.
cgicc::HTTPResponseHeader::~HTTPResponseHeader
virtual ~HTTPResponseHeader()
Delete this HTTPResponseHeader.
cgicc::HTTPResponseHeader::addHeader
HTTPResponseHeader & addHeader(const std::string &name, const std::string &value)
Add a general, response, or entity header to this one.
cgicc::HTTPResponseHeader::getCookies
const std::vector< HTTPCookie > & getCookies() const
Get a list of all cookies associated with this header.
Definition: HTTPResponseHeader.h:147
cgicc::HTTPResponseHeader::getHeaders
const std::vector< std::string > & getHeaders() const
Get a list of all additional headers.
Definition: HTTPResponseHeader.h:128
cgicc::HTTPResponseHeader::setCookie
HTTPResponseHeader & setCookie(const HTTPCookie &cookie)
Set a cookie to go out with this HTTPResponseHeader.
cgicc::HTTPResponseHeader::getReasonPhrase
HTTPResponseHeader & getReasonPhrase(const std::string &reason_phrase)
Get the reason phrase associated with the stats code.
Definition: HTTPResponseHeader.h:226
cgicc::MStreamable
Mix-in streamable interface.
Definition: MStreamable.h:67
cgicc
The namespace containing the cgicc library.
Definition: Cgicc.h:52