| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2024 Christian Mazakas | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/http_proto | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_HTTP_PROTO_MESSAGE_VIEW_BASE_HPP | ||
| 12 | #define BOOST_HTTP_PROTO_MESSAGE_VIEW_BASE_HPP | ||
| 13 | |||
| 14 | #include <boost/http_proto/detail/config.hpp> | ||
| 15 | #include <boost/http_proto/fields_view_base.hpp> | ||
| 16 | #include <boost/http_proto/metadata.hpp> | ||
| 17 | #include <boost/url/grammar/recycled.hpp> | ||
| 18 | #include <boost/url/grammar/type_traits.hpp> | ||
| 19 | #include <memory> | ||
| 20 | #include <string> | ||
| 21 | |||
| 22 | namespace boost { | ||
| 23 | namespace http_proto { | ||
| 24 | |||
| 25 | /** Provides message metadata for requests and responses | ||
| 26 | */ | ||
| 27 | class BOOST_SYMBOL_VISIBLE | ||
| 28 | message_view_base | ||
| 29 | : public virtual fields_view_base | ||
| 30 | { | ||
| 31 | friend class request_view; | ||
| 32 | friend class response_view; | ||
| 33 | friend class message_base; | ||
| 34 | |||
| 35 | 734 | message_view_base() noexcept | |
| 36 | // VFALCO This ctor-init has to be | ||
| 37 | // here even though it isn't called, | ||
| 38 | // so nullptr doesn't matter. | ||
| 39 | 734 | : fields_view_base(nullptr) | |
| 40 | { | ||
| 41 | 734 | } | |
| 42 | |||
| 43 | explicit | ||
| 44 | message_view_base( | ||
| 45 | detail::header const* ph) noexcept | ||
| 46 | : fields_view_base(ph) | ||
| 47 | { | ||
| 48 | } | ||
| 49 | |||
| 50 | public: | ||
| 51 | //-------------------------------------------- | ||
| 52 | // | ||
| 53 | // Metadata | ||
| 54 | // | ||
| 55 | //-------------------------------------------- | ||
| 56 | |||
| 57 | /** Return the type of payload of this message | ||
| 58 | */ | ||
| 59 | auto | ||
| 60 | 38 | payload() const noexcept -> | |
| 61 | http_proto::payload | ||
| 62 | { | ||
| 63 | 38 | return ph_->md.payload; | |
| 64 | } | ||
| 65 | |||
| 66 | /** Return the payload size | ||
| 67 | |||
| 68 | When @ref payload returns @ref payload::size, | ||
| 69 | this function returns the number of octets | ||
| 70 | in the actual message payload. | ||
| 71 | */ | ||
| 72 | std::uint64_t | ||
| 73 | 2 | payload_size() const noexcept | |
| 74 | { | ||
| 75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | BOOST_ASSERT( |
| 76 | payload() == payload::size); | ||
| 77 | 2 | return ph_->md.payload_size; | |
| 78 | } | ||
| 79 | |||
| 80 | /** Return true if semantics indicate connection persistence | ||
| 81 | */ | ||
| 82 | bool | ||
| 83 | 22 | keep_alive() const noexcept | |
| 84 | { | ||
| 85 | 22 | return ph_->keep_alive(); | |
| 86 | } | ||
| 87 | |||
| 88 | /** Return metadata about the message | ||
| 89 | */ | ||
| 90 | auto | ||
| 91 | 142 | metadata() const noexcept -> | |
| 92 | http_proto::metadata const& | ||
| 93 | { | ||
| 94 | 142 | return ph_->md; | |
| 95 | } | ||
| 96 | |||
| 97 | /** Return true if the message is using a chunked | ||
| 98 | transfer encoding. | ||
| 99 | */ | ||
| 100 | bool | ||
| 101 | 30 | chunked() const noexcept | |
| 102 | { | ||
| 103 | 30 | return ph_->md.transfer_encoding.is_chunked; | |
| 104 | } | ||
| 105 | |||
| 106 | /** Return true if the message uses some form of | ||
| 107 | compression (deflate, gzip). | ||
| 108 | */ | ||
| 109 | bool | ||
| 110 | 26 | compressed() const noexcept | |
| 111 | { | ||
| 112 | return | ||
| 113 | 26 | ph_->md.content_encoding.coding != | |
| 114 | 26 | content_coding_type::none; | |
| 115 | } | ||
| 116 | |||
| 117 | enum content_coding_type | ||
| 118 | content_coding() const noexcept | ||
| 119 | { | ||
| 120 | return ph_->md.content_encoding.coding; | ||
| 121 | } | ||
| 122 | }; | ||
| 123 | |||
| 124 | } // http_proto | ||
| 125 | } // boost | ||
| 126 | |||
| 127 | #endif | ||
| 128 |