root/http/response.hh

Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 3.6 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago)

Update the project blurb

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_HTTP_RESPONSE_HH
21#define GUARD_HTTP_RESPONSE_HH
22
23#include "session.hh"
24
25#include <boost/asio.hpp>
26#include <vector>
27
28namespace http
29{
30        class connection;
31        class request;
32        class response : private boost::noncopyable
33        {
34        public:
35                class factory
36                {
37                        boost::shared_ptr<connection> conn;
38                        bool v11;
39                        bool close;
40                        bool no_body;
41                public:
42                        factory(boost::shared_ptr<connection> conn)
43                                : conn(conn), v11(true), close(true),
44                                  no_body(false)
45                                {}
46                        void set_v11(bool val) { v11 = val; }
47                        void set_close(bool val) { close = val; }
48                        void set_no_body(bool val) { no_body = val; }
49
50                        boost::shared_ptr<response> operator()(std::string s)
51                                const {
52                                boost::shared_ptr<response> rv
53                                        (new response(conn, v11, close,
54                                                      no_body, s));
55                                return rv;
56                        }
57                };
58                typedef boost::asio::const_buffers_1
59                const_buffer_sequence;
60
61                std::ostream &body(std::string content_type);
62                std::string logbit() const { return logline; }
63
64                void complete();
65
66                const_buffer_sequence get_buffer() const {
67                        assert(completed);
68                        return boost::asio::buffer(buffer.data(),
69                                                   buffer.size());
70                }
71
72                std::string get_string() const {
73                        assert(completed);
74                        return std::string(buffer.begin(), buffer.end());
75                }
76
77                bool get_close() const { return close; }
78                void add_header(std::string name, std::string body) {
79                        hdrs << name << ": " << body << "\r\n";
80                }
81                void set_session(boost::shared_ptr<request> req,
82                                 boost::shared_ptr<session>);
83        private:
84                boost::shared_ptr<connection> conn;
85                std::ostringstream hdrs;
86                std::ostringstream bdy;
87                const bool close;
88                const bool no_body;
89
90                // constructed by get_buffer
91                std::vector<char> buffer;
92                bool completed;
93
94                std::string logline;
95
96                response(boost::shared_ptr<connection> conn,
97                         bool v11, bool close, bool no_body,
98                         std::string respline);
99        };
100}
101
102#endif /* GUARD_HTTP_RESPONSE_HH */
Note: See TracBrowser for help on using the browser.