-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmessage_base.hpp
More file actions
190 lines (154 loc) · 4.23 KB
/
message_base.hpp
File metadata and controls
190 lines (154 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//
// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2024 Christian Mazakas
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/http_proto
//
#ifndef BOOST_HTTP_PROTO_MESSAGE_BASE_HPP
#define BOOST_HTTP_PROTO_MESSAGE_BASE_HPP
#include <boost/http_proto/detail/config.hpp>
#include <boost/http_proto/fields_base.hpp>
#include <boost/core/detail/string_view.hpp>
namespace boost {
namespace http_proto {
/** Mixin for common metadata in HTTP request and response messages.
This type is useful for modifying common
properties shared by both requests
and responses.
@see
@ref response,
@ref request,
@ref metadata.
*/
class message_base
: public fields_base
{
friend class request;
friend class response;
using fields_base::fields_base;
public:
//--------------------------------------------
//
// Observers
//
//--------------------------------------------
/** Return the type of payload of this message.
*/
auto
payload() const noexcept ->
http_proto::payload
{
return h_.md.payload;
}
/** Return the payload size.
When @ref payload returns @ref payload::size,
this function returns the number of octets
in the actual message payload.
@return The number of octets in the
actual message payload.
*/
std::uint64_t
payload_size() const noexcept
{
BOOST_ASSERT(
payload() == payload::size);
return h_.md.payload_size;
}
/** Return true if semantics indicate
connection persistence.
*/
bool
keep_alive() const noexcept
{
return h_.keep_alive();
}
/** Return metadata about the message.
*/
auto
metadata() const noexcept ->
http_proto::metadata const&
{
return h_.md;
}
/** Return true if the message is using a chunked
transfer encoding.
*/
bool
chunked() const noexcept
{
return h_.md.transfer_encoding.is_chunked;
}
/** Return the HTTP-version.
*/
http_proto::version
version() const noexcept
{
return h_.version;
}
//--------------------------------------------
//
// Modifiers
//
//--------------------------------------------
/** Set the payload size.
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
Exception thrown if max capacity exceeded.
@throw std::length_error
Max capacity would be exceeded.
@param n The payload size to set.
*/
BOOST_HTTP_PROTO_DECL
void
set_payload_size(
std::uint64_t n);
/** Set the Content-Length to the specified value.
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
Exception thrown if max capacity exceeded.
@throw std::length_error
Max capacity would be exceeded.
@param n The Content-Length to set.
*/
BOOST_HTTP_PROTO_DECL
void
set_content_length(
std::uint64_t n);
/** Set whether the payload is chunked.
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
Exception thrown if max capacity exceeded.
@throw std::length_error
Max capacity would be exceeded.
@param value The value to set.
*/
BOOST_HTTP_PROTO_DECL
void
set_chunked(bool value);
/** Set whether the connection should stay open.
Even when keep-alive is set to true, the
semantics of the other header fields may
require the connection to be closed. For
example when there is no content length
specified in a response.
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
Exception thrown if max capacity exceeded.
@throw std::length_error
Max capacity would be exceeded.
@param value The value to set.
*/
BOOST_HTTP_PROTO_DECL
void
set_keep_alive(bool value);
};
} // http_proto
} // boost
#endif