reply.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 by Marc Boris Duerner, Tommi Maekitalo
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef cxxtools_Http_Reply_h
30 #define cxxtools_Http_Reply_h
31 
32 #include <cxxtools/http/api.h>
34 #include <string>
35 #include <sstream>
36 
37 namespace cxxtools {
38 
39 namespace http {
40 
41 class Request;
42 
43 class Reply
44 {
45  ReplyHeader _header;
46  std::ostringstream _body;
47 
48  public:
50  { }
51 
53  { return _header; }
54 
55  const ReplyHeader& header() const
56  { return _header; }
57 
58  void setHeader(const char* key, const char* value)
59  {
60  _header.setHeader(key, value);
61  }
62 
63  void addHeader(const char* key, const char* value)
64  {
65  _header.addHeader(key, value);
66  }
67 
68  void removeHeader(const char* key)
69  {
70  _header.removeHeader(key);
71  }
72 
73  const char* getHeader(const char* key) const
74  {
75  return _header.getHeader(key);
76  }
77 
78  bool hasHeader(const char* key) const
79  {
80  return _header.hasHeader(key);
81  }
82 
83  void clear()
84  {
85  _header.clear();
86  _body.clear();
87  _body.str(std::string());
88  }
89 
90  unsigned httpReturnCode() const
91  { return _header.httpReturnCode(); }
92 
93  const std::string& httpReturnText() const
94  { return _header.httpReturnText(); }
95 
96  void httpReturn(unsigned c, const std::string& t)
97  { _header.httpReturn(c, t); }
98 
99  std::string bodyStr() const
100  { return _body.str(); }
101 
102  std::ostream& body()
103  { return _body; }
104 
105  std::size_t bodySize() const
106  { return _body.str().size(); }
107 
108  void sendBody(std::ostream& out) const
109  { out << _body.str(); }
110 
111 };
112 
113 } // namespace http
114 
115 } // namespace cxxtools
116 
117 #endif