Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) |
3 |
|
|
// |
4 |
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 |
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 |
|
|
// |
7 |
|
|
// Official repository: https://github.com/CPPAlliance/http_proto |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_HTTP_PROTO_RESPONSE_HPP |
11 |
|
|
#define BOOST_HTTP_PROTO_RESPONSE_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/http_proto/detail/config.hpp> |
14 |
|
|
#include <boost/http_proto/message_base.hpp> |
15 |
|
|
#include <boost/http_proto/response_view.hpp> |
16 |
|
|
|
17 |
|
|
namespace boost { |
18 |
|
|
namespace http_proto { |
19 |
|
|
|
20 |
|
|
/** Container for HTTP responses |
21 |
|
|
*/ |
22 |
|
|
class BOOST_SYMBOL_VISIBLE |
23 |
|
|
response |
24 |
|
|
: public message_base |
25 |
|
|
{ |
26 |
|
|
public: |
27 |
|
|
/** Constructor |
28 |
|
|
*/ |
29 |
|
|
BOOST_HTTP_PROTO_DECL |
30 |
|
|
response() noexcept; |
31 |
|
|
|
32 |
|
|
/** Constructor |
33 |
|
|
*/ |
34 |
|
|
BOOST_HTTP_PROTO_DECL |
35 |
|
|
explicit |
36 |
|
|
response(string_view s); |
37 |
|
|
|
38 |
|
|
/** Constructor |
39 |
|
|
|
40 |
|
|
The moved-from object will be |
41 |
|
|
left in the default-constructed |
42 |
|
|
state. |
43 |
|
|
*/ |
44 |
|
|
BOOST_HTTP_PROTO_DECL |
45 |
|
|
response(response&& other) noexcept; |
46 |
|
|
|
47 |
|
|
/** Constructor |
48 |
|
|
*/ |
49 |
|
|
BOOST_HTTP_PROTO_DECL |
50 |
|
|
response(response const& other); |
51 |
|
|
|
52 |
|
|
/** Constructor |
53 |
|
|
*/ |
54 |
|
|
BOOST_HTTP_PROTO_DECL |
55 |
|
|
response( |
56 |
|
|
response_view const& other); |
57 |
|
|
|
58 |
|
|
/** Assignment |
59 |
|
|
*/ |
60 |
|
|
BOOST_HTTP_PROTO_DECL |
61 |
|
|
response& |
62 |
|
|
operator=( |
63 |
|
|
response&& other) noexcept; |
64 |
|
|
|
65 |
|
|
/** Assignment |
66 |
|
|
*/ |
67 |
|
|
response& |
68 |
|
|
operator=( |
69 |
|
|
response const& other) |
70 |
|
|
{ |
71 |
|
|
copy_impl(*other.ph_); |
72 |
|
|
return *this; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
/** Assignment |
76 |
|
|
*/ |
77 |
|
|
response& |
78 |
|
|
operator=( |
79 |
|
|
response_view const& other) |
80 |
|
|
{ |
81 |
|
|
copy_impl(*other.ph_); |
82 |
|
|
return *this; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
/** Constructor |
86 |
|
|
*/ |
87 |
|
|
BOOST_HTTP_PROTO_DECL |
88 |
|
|
response( |
89 |
|
|
http_proto::status sc, |
90 |
|
|
http_proto::version v); |
91 |
|
|
|
92 |
|
|
/** Return a read-only view to the response |
93 |
|
|
*/ |
94 |
|
|
operator |
95 |
|
|
response_view() const noexcept |
96 |
|
|
{ |
97 |
|
|
return response_view(ph_); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
//-------------------------------------------- |
101 |
|
|
// |
102 |
|
|
// Observers |
103 |
|
|
// |
104 |
|
|
//-------------------------------------------- |
105 |
|
|
|
106 |
|
|
/** Return the reason string |
107 |
|
|
|
108 |
|
|
This field is obsolete in HTTP/1 |
109 |
|
|
and should only be used for display |
110 |
|
|
purposes. |
111 |
|
|
*/ |
112 |
|
|
string_view |
113 |
|
|
reason() const noexcept |
114 |
|
|
{ |
115 |
|
|
return string_view( |
116 |
|
|
ph_->cbuf + 13, |
117 |
|
|
ph_->prefix - 15); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/** Return the status code |
121 |
|
|
*/ |
122 |
|
|
http_proto::status |
123 |
|
|
status() const noexcept |
124 |
|
|
{ |
125 |
|
|
return ph_->res.status; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
/** Return the status code |
129 |
|
|
*/ |
130 |
|
|
unsigned short |
131 |
|
|
status_int() const noexcept |
132 |
|
|
{ |
133 |
|
|
return ph_->res.status_int; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
/** Return the HTTP version |
137 |
|
|
*/ |
138 |
|
|
http_proto::version |
139 |
|
|
version() const noexcept |
140 |
|
|
{ |
141 |
|
|
return ph_->version; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
//-------------------------------------------- |
145 |
|
|
// |
146 |
|
|
// Modifiers |
147 |
|
|
// |
148 |
|
|
//-------------------------------------------- |
149 |
|
|
|
150 |
|
|
/** Set the version, status code of the response |
151 |
|
|
|
152 |
|
|
The reason phrase will be set to the |
153 |
|
|
standard text for the specified status |
154 |
|
|
code. |
155 |
|
|
|
156 |
|
|
@par sc The status code. This must not be |
157 |
|
|
@ref http_proto::status::unknown. |
158 |
|
|
|
159 |
|
|
@par v The HTTP-version. |
160 |
|
|
*/ |
161 |
|
|
void |
162 |
|
✗ |
set_start_line( |
163 |
|
|
http_proto::status sc, |
164 |
|
|
http_proto::version v = |
165 |
|
|
http_proto::version::http_1_1) |
166 |
|
|
{ |
167 |
|
✗ |
set_impl( |
168 |
|
|
sc, |
169 |
|
|
static_cast< |
170 |
|
|
unsigned short>(sc), |
171 |
|
|
obsolete_reason(sc), |
172 |
|
|
v); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
void |
176 |
|
|
set_start_line( |
177 |
|
|
unsigned short si, |
178 |
|
|
string_view reason, |
179 |
|
|
http_proto::version v) |
180 |
|
|
{ |
181 |
|
|
set_impl( |
182 |
|
|
int_to_status(si), |
183 |
|
|
si, |
184 |
|
|
reason, |
185 |
|
|
v); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
/** Swap this with another instance |
189 |
|
|
*/ |
190 |
|
|
void |
191 |
|
✗ |
swap(response& other) noexcept |
192 |
|
|
{ |
193 |
|
✗ |
h_.swap(other.h_); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
/** Swap two instances |
197 |
|
|
*/ |
198 |
|
|
// hidden friend |
199 |
|
|
friend |
200 |
|
|
void |
201 |
|
|
swap( |
202 |
|
|
response& t0, |
203 |
|
|
response& t1) noexcept |
204 |
|
|
{ |
205 |
|
|
t0.swap(t1); |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
private: |
209 |
|
|
BOOST_HTTP_PROTO_DECL |
210 |
|
|
void |
211 |
|
|
set_impl( |
212 |
|
|
http_proto::status sc, |
213 |
|
|
unsigned short si, |
214 |
|
|
string_view reason, |
215 |
|
|
http_proto::version v); |
216 |
|
|
}; |
217 |
|
|
|
218 |
|
|
} // http_proto |
219 |
|
|
} // boost |
220 |
|
|
|
221 |
|
|
#endif |
222 |
|
|
|