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
44namespace 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
96
97 // ============================================================
98
101
109 addHeader(const std::string& header);
110
119 addHeader(const std::string& name,
120 const std::string& value);
121
127 inline const std::vector<std::string>&
129 { return fHeaders; }
131
134
140 setCookie(const HTTPCookie& cookie);
141
146 inline const std::vector<HTTPCookie>&
148 { return fCookies; }
150
151 // ============================================================
152
157
164 inline const std::string&
166 { return fHTTPVersion; }
167
174 inline int
176 { return fStatusCode; }
177
184 inline std::string
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:
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_ */
An HTTP Cookie.
Abstract base class for all streamable objects.
An HTTP cookie.
Definition: HTTPCookie.h:59
Generic HTTP response header.
const std::string & getHTTPVersion() const
Get the HTTP version.
HTTPResponseHeader & getStatusCode(int status_code)
Get the 3-digit status code.
HTTPResponseHeader & addHeader(const std::string &header)
Add a general, response, or entity header to this one.
HTTPResponseHeader & getHTTPVersion(const std::string &http_version)
Set the HTTP version.
int getStatusCode() const
Get the 3-digit status code.
virtual void render(std::ostream &out) const
Write this object to a stream.
std::string getReasonPhrase() const
Get the reason phrase associated with the stats code.
HTTPResponseHeader(const std::string &http_version, int status_code, const std::string &reason_phrase)
Create a new HTTP response header.
virtual ~HTTPResponseHeader()
Delete this HTTPResponseHeader.
HTTPResponseHeader & addHeader(const std::string &name, const std::string &value)
Add a general, response, or entity header to this one.
const std::vector< HTTPCookie > & getCookies() const
Get a list of all cookies associated with this header.
const std::vector< std::string > & getHeaders() const
Get a list of all additional headers.
HTTPResponseHeader & setCookie(const HTTPCookie &cookie)
Set a cookie to go out with this HTTPResponseHeader.
HTTPResponseHeader & getReasonPhrase(const std::string &reason_phrase)
Get the reason phrase associated with the stats code.
Mix-in streamable interface.
Definition: MStreamable.h:67
The namespace containing the cgicc library.
Definition: Cgicc.h:52

GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Fri Mar 1 2024 08:39:41 for cgicc by doxygen 1.9.6