Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.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_MESSAGE_VIEW_BASE_HPP | ||
11 | #define BOOST_HTTP_PROTO_MESSAGE_VIEW_BASE_HPP | ||
12 | |||
13 | #include <boost/http_proto/detail/config.hpp> | ||
14 | #include <boost/http_proto/fields_view_base.hpp> | ||
15 | #include <boost/url/grammar/recycled.hpp> | ||
16 | #include <boost/url/grammar/type_traits.hpp> | ||
17 | #include <memory> | ||
18 | #include <string> | ||
19 | |||
20 | namespace boost { | ||
21 | namespace http_proto { | ||
22 | |||
23 | /** Provides message metadata for requests and responses | ||
24 | */ | ||
25 | class BOOST_SYMBOL_VISIBLE | ||
26 | message_view_base | ||
27 | : public virtual fields_view_base | ||
28 | { | ||
29 | friend class request_view; | ||
30 | friend class response_view; | ||
31 | friend class message_base; | ||
32 | |||
33 | 365 | message_view_base() noexcept | |
34 | // VFALCO This ctor-init has to be | ||
35 | // here even though it isn't called, | ||
36 | // so nullptr doesn't matter. | ||
37 | 365 | : fields_view_base(nullptr) | |
38 | { | ||
39 | 365 | } | |
40 | |||
41 | explicit | ||
42 | message_view_base( | ||
43 | detail::header const* ph) noexcept | ||
44 | : fields_view_base(ph) | ||
45 | { | ||
46 | } | ||
47 | |||
48 | public: | ||
49 | //-------------------------------------------- | ||
50 | // | ||
51 | // Metadata | ||
52 | // | ||
53 | //-------------------------------------------- | ||
54 | |||
55 | /** Return the type of payload of this message | ||
56 | */ | ||
57 | auto | ||
58 | 38 | payload() const noexcept -> | |
59 | http_proto::payload | ||
60 | { | ||
61 | 38 | return ph_->md.payload; | |
62 | } | ||
63 | |||
64 | /** Return the payload size | ||
65 | |||
66 | When @ref payload returns @ref payload::size, | ||
67 | this function returns the number of octets | ||
68 | in the actual message payload. | ||
69 | */ | ||
70 | std::uint64_t | ||
71 | 2 | payload_size() const noexcept | |
72 | { | ||
73 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | BOOST_ASSERT( |
74 | payload() == payload::size); | ||
75 | 2 | return ph_->md.payload_size; | |
76 | } | ||
77 | |||
78 | /** Return true if semantics indicate connection persistence | ||
79 | */ | ||
80 | bool | ||
81 | 22 | keep_alive() const noexcept | |
82 | { | ||
83 | 22 | return ph_->keep_alive(); | |
84 | } | ||
85 | |||
86 | /** Return metadata about the message | ||
87 | */ | ||
88 | auto | ||
89 | 123 | metadata() const noexcept -> | |
90 | http_proto::metadata const& | ||
91 | { | ||
92 | 123 | return ph_->md; | |
93 | } | ||
94 | }; | ||
95 | |||
96 | } // http_proto | ||
97 | } // boost | ||
98 | |||
99 | #endif | ||
100 |