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 |
|
|
The moved-from object will be |
35 |
|
|
left in the default-constructed |
36 |
|
|
state. |
37 |
|
|
*/ |
38 |
|
|
BOOST_HTTP_PROTO_DECL |
39 |
|
|
response(response&& other) noexcept; |
40 |
|
|
|
41 |
|
|
/** Constructor |
42 |
|
|
*/ |
43 |
|
|
BOOST_HTTP_PROTO_DECL |
44 |
|
|
response(response const& other); |
45 |
|
|
|
46 |
|
|
/** Constructor |
47 |
|
|
*/ |
48 |
|
|
BOOST_HTTP_PROTO_DECL |
49 |
|
|
response( |
50 |
|
|
response_view const& other); |
51 |
|
|
|
52 |
|
|
/** Assignment |
53 |
|
|
*/ |
54 |
|
|
BOOST_HTTP_PROTO_DECL |
55 |
|
|
response& |
56 |
|
|
operator=( |
57 |
|
|
response&& other) noexcept; |
58 |
|
|
|
59 |
|
|
/** Assignment |
60 |
|
|
*/ |
61 |
|
|
response& |
62 |
|
|
operator=( |
63 |
|
|
response const& other) |
64 |
|
|
{ |
65 |
|
|
copy_impl(*other.ph_); |
66 |
|
|
return *this; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
/** Assignment |
70 |
|
|
*/ |
71 |
|
|
response& |
72 |
|
|
operator=( |
73 |
|
|
response_view const& other) |
74 |
|
|
{ |
75 |
|
|
copy_impl(*other.ph_); |
76 |
|
|
return *this; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
/** Constructor |
80 |
|
|
*/ |
81 |
|
|
BOOST_HTTP_PROTO_DECL |
82 |
|
|
response( |
83 |
|
|
http_proto::status sc, |
84 |
|
|
http_proto::version v); |
85 |
|
|
|
86 |
|
|
/** Return a read-only view to the response |
87 |
|
|
*/ |
88 |
|
|
operator |
89 |
|
|
response_view() const noexcept |
90 |
|
|
{ |
91 |
|
|
return response_view(ph_); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
//-------------------------------------------- |
95 |
|
|
// |
96 |
|
|
// Observers |
97 |
|
|
// |
98 |
|
|
//-------------------------------------------- |
99 |
|
|
|
100 |
|
|
/** Return the reason string |
101 |
|
|
|
102 |
|
|
This field is obsolete in HTTP/1 |
103 |
|
|
and should only be used for display |
104 |
|
|
purposes. |
105 |
|
|
*/ |
106 |
|
|
string_view |
107 |
|
|
reason() const noexcept |
108 |
|
|
{ |
109 |
|
|
return string_view( |
110 |
|
|
ph_->cbuf + 13, |
111 |
|
|
ph_->prefix - 15); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
/** Return the status code |
115 |
|
|
*/ |
116 |
|
|
http_proto::status |
117 |
|
|
status() const noexcept |
118 |
|
|
{ |
119 |
|
|
return ph_->res.status; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
/** Return the status code |
123 |
|
|
*/ |
124 |
|
|
unsigned short |
125 |
|
|
status_int() const noexcept |
126 |
|
|
{ |
127 |
|
|
return ph_->res.status_int; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/** Return the HTTP version |
131 |
|
|
*/ |
132 |
|
|
http_proto::version |
133 |
|
|
version() const noexcept |
134 |
|
|
{ |
135 |
|
|
return ph_->version; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
//-------------------------------------------- |
139 |
|
|
// |
140 |
|
|
// Modifiers |
141 |
|
|
// |
142 |
|
|
//-------------------------------------------- |
143 |
|
|
|
144 |
|
|
/** Set the version, status code of the response |
145 |
|
|
|
146 |
|
|
The reason phrase will be set to the |
147 |
|
|
standard text for the specified status |
148 |
|
|
code. |
149 |
|
|
|
150 |
|
|
@par sc The status code. This must not be |
151 |
|
|
@ref http_proto::status::unknown. |
152 |
|
|
|
153 |
|
|
@par v The HTTP-version. |
154 |
|
|
*/ |
155 |
|
|
void |
156 |
|
✗ |
set_start_line( |
157 |
|
|
http_proto::status sc, |
158 |
|
|
http_proto::version v = |
159 |
|
|
http_proto::version::http_1_1) |
160 |
|
|
{ |
161 |
|
✗ |
set_impl( |
162 |
|
|
sc, |
163 |
|
|
static_cast< |
164 |
|
|
unsigned short>(sc), |
165 |
|
|
obsolete_reason(sc), |
166 |
|
|
v); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
void |
170 |
|
66 |
set_start_line( |
171 |
|
|
unsigned short si, |
172 |
|
|
string_view reason, |
173 |
|
|
http_proto::version v) |
174 |
|
|
{ |
175 |
|
66 |
set_impl( |
176 |
|
|
int_to_status(si), |
177 |
|
|
si, |
178 |
|
|
reason, |
179 |
|
|
v); |
180 |
|
66 |
} |
181 |
|
|
|
182 |
|
|
/** Swap this with another instance |
183 |
|
|
*/ |
184 |
|
|
void |
185 |
|
✗ |
swap(response& other) noexcept |
186 |
|
|
{ |
187 |
|
✗ |
h_.swap(other.h_); |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
/** Swap two instances |
191 |
|
|
*/ |
192 |
|
|
// hidden friend |
193 |
|
|
friend |
194 |
|
|
void |
195 |
|
|
swap( |
196 |
|
|
response& t0, |
197 |
|
|
response& t1) noexcept |
198 |
|
|
{ |
199 |
|
|
t0.swap(t1); |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
private: |
203 |
|
|
BOOST_HTTP_PROTO_DECL |
204 |
|
|
void |
205 |
|
|
set_impl( |
206 |
|
|
http_proto::status sc, |
207 |
|
|
unsigned short si, |
208 |
|
|
string_view reason, |
209 |
|
|
http_proto::version v); |
210 |
|
|
}; |
211 |
|
|
|
212 |
|
|
} // http_proto |
213 |
|
|
} // boost |
214 |
|
|
|
215 |
|
|
#endif |
216 |
|
|
|