AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
response.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2020 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <string>
23#include <sstream>
24#include <functional>
25#include <ostream>
26#include <istream>
27#include <memory>
28#include <map>
29
30#include "rest/headers.hpp"
31#include "rest/mapperRegistry.hpp"
32
33
34namespace anch::rest {
35
45 class Response {
46 class Builder;
47
48 // Attributes +
49 private:
51 uint16_t _code;
52
54 anch::rest::Headers _headers;
55
58
60 std::function<void(std::ostream&)> _bodyWriter;
61
63 std::shared_ptr<std::istream> _input;
64 // Attributes -
65
66 public:
67 // Constructors +
72
78 Response(uint16_t code);
79
85 Response(const Response& res) = delete;
86
93 // Constructors -
94
95 public:
96 // Destructor +
100 virtual ~Response();
101 // Destructor -
102
103 // Methods +
109 static Builder builder();
110 // Methods -
111
112 // Operators +
113 public:
122 // Operators -
123
124 // Accessors +
130 uint16_t getStatus() const;
131
137 void setStatus(uint16_t code);
138
145
152 void setHeaders(const anch::rest::Headers& headers);
153
159 std::string getContentType() const;
160
166 void setContentType(const std::string& contentType);
167
175 template<typename T>
176 void setBody(T body);
177
183 void writeBody(std::ostream& out) const;
184 // Accessors -
185
186 };
187
198 private:
200 Response _response;
201
202 public:
203 // Constructors +
208
215 // Constructors -
216
217 public:
218 // Destructor +
222 virtual ~Builder();
223 // Destructor -
224
225 // Methods +
233 Builder status(uint16_t code);
234
243 Builder header(const std::string& name, const std::string& value);
244
253 Builder header(const std::string& name, const std::vector<std::string>& values);
254
264
272 Builder contentType(const std::string& contentType);
273
279 Builder body(const std::string& body);
280
286 Builder body(const char* const body);
287
295 template<typename T>
297
304 // Methods -
305 };
306
307}
308
309#include "rest/impl/response.hpp"
HTTP headers.
Definition headers.hpp:44
Definition mapperRegistry.hpp:49
HTTP response builder.
Definition response.hpp:197
Builder header(const std::string &name, const std::string &value)
Builder header(const std::string &name, const std::vector< std::string > &values)
Builder headers(const anch::rest::Headers &headers)
Builder body(const char *const body)
Builder contentType(const std::string &contentType)
Builder status(uint16_t code)
Builder body(const std::string &body)
Builder(Builder &&builder)
Response & operator=(Response &&other)
void setHeaders(const anch::rest::Headers &headers)
const anch::rest::Headers & getHeaders() const
void setContentType(const std::string &contentType)
uint16_t getStatus() const
static Builder builder()
std::string getContentType() const
Response(Response &&res)
void writeBody(std::ostream &out) const
Response(const Response &res)=delete
void setStatus(uint16_t code)
void setBody(T body)
Response(uint16_t code)