Malloy
Loading...
Searching...
No Matches
response.hpp
1#pragma once
2
3#include "types.hpp"
4#include "cookie.hpp"
5#include "../utils.hpp"
6
7#include <boost/beast/core.hpp>
8#include <boost/beast/http.hpp>
9#include <boost/beast/version.hpp>
10
11#include <filesystem>
12
13namespace malloy::http
14{
15
19 template<typename Body = boost::beast::http::string_body, typename Fields = boost::beast::http::fields>
20 class response :
21 public boost::beast::http::response<Body, Fields>
22 {
23 using msg_t = boost::beast::http::response<Body, Fields>;
24
25 public:
29 response() = default;
30
36 explicit
37 response(msg_t&& msg)
38 {
39 msg_t::operator=(std::move(msg));
40 }
41
47 explicit
48 response(const boost::beast::http::response_header<Fields>& header) :
49 msg_t{ header }
50 {
51 }
52
58 explicit
59 response(boost::beast::http::response_header<Fields>&& header) :
60 msg_t{ std::move(header) }
61 {
62 }
63
69 explicit
70 response(const status& status_)
71 {
72 msg_t::result(status_);
73 }
74
80 response(const response& other) = default;
81
87 response(response&& other) noexcept = default;
88
92 virtual
93 ~response() = default;
94
101 response&
102 operator=(const response& rhs) = default;
103
110 response&
111 operator=(response&& rhs) noexcept = default;
112
118 void
120
126 [[nodiscard]]
128 status() const { return msg_t::result(); }
129
135 void
137 {
138 msg_t::insert(malloy::http::field::set_cookie, c.to_string());
139 }
140 };
141
142}
143
144#include <sstream>
145
146namespace malloy
147{
148
149 template<typename Body, typename Fields>
150 [[nodiscard]]
151 std::string
152 to_string(const http::response<Body, Fields>& r)
153 {
154 std::ostringstream ss;
155 ss << r;
156
157 return ss.str();
158 }
159
160}
Definition: cookie.hpp:20
Definition: response.hpp:22
void set_status(http::status status)
Definition: response.hpp:119
response & operator=(const response &rhs)=default
response(boost::beast::http::response_header< Fields > &&header)
Definition: response.hpp:59
response(msg_t &&msg)
Definition: response.hpp:37
void add_cookie(const cookie &c)
Definition: response.hpp:136
response(const boost::beast::http::response_header< Fields > &header)
Definition: response.hpp:48
response(const response &other)=default
response & operator=(response &&rhs) noexcept=default
http::status status() const
Definition: response.hpp:128
virtual ~response()=default
response(response &&other) noexcept=default
response(const status &status_)
Definition: response.hpp:70
Definition: cookie.hpp:8
boost::beast::http::status status
Definition: types.hpp:23
Definition: controller.hpp:32
std::string_view to_string(const malloy::http::method method)
Definition: http.hpp:26