| 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_BASE_HPP | ||
| 12 | #define BOOST_HTTP_PROTO_MESSAGE_BASE_HPP | ||
| 13 | |||
| 14 | #include <boost/http_proto/detail/config.hpp> | ||
| 15 | #include <boost/http_proto/fields_base.hpp> | ||
| 16 | #include <boost/http_proto/message_view_base.hpp> | ||
| 17 | #include <boost/core/detail/string_view.hpp> | ||
| 18 | |||
| 19 | namespace boost { | ||
| 20 | namespace http_proto { | ||
| 21 | |||
| 22 | /** Provides message metadata for requests and responses | ||
| 23 | */ | ||
| 24 | class message_base | ||
| 25 | : public fields_base | ||
| 26 | , public message_view_base | ||
| 27 | { | ||
| 28 | friend class request_base; | ||
| 29 | friend class response_base; | ||
| 30 | |||
| 31 | explicit | ||
| 32 | 132 | message_base( | |
| 33 | detail::kind k) noexcept | ||
| 34 | : fields_view_base( | ||
| 35 | &this->fields_base::h_) | ||
| 36 | 132 | , fields_base(k) | |
| 37 | { | ||
| 38 | 132 | } | |
| 39 | |||
| 40 | 44 | message_base( | |
| 41 | detail::kind k, | ||
| 42 | char* storage, | ||
| 43 | std::size_t storage_size) noexcept | ||
| 44 | : fields_view_base(&this->fields_base::h_) | ||
| 45 | , fields_base( | ||
| 46 | 44 | k, storage, storage_size) | |
| 47 | { | ||
| 48 | 44 | } | |
| 49 | |||
| 50 | 8 | message_base( | |
| 51 | detail::kind k, | ||
| 52 | std::size_t storage_size) | ||
| 53 | : fields_view_base( | ||
| 54 | &this->fields_base::h_) | ||
| 55 | , fields_base( | ||
| 56 | 8 | k, storage_size) | |
| 57 | { | ||
| 58 | 8 | } | |
| 59 | |||
| 60 | 20 | message_base( | |
| 61 | detail::kind k, | ||
| 62 | std::size_t storage_size, | ||
| 63 | std::size_t max_storage_size) | ||
| 64 | : fields_view_base( | ||
| 65 | &this->fields_base::h_) | ||
| 66 | , fields_base( | ||
| 67 | 20 | k, storage_size, max_storage_size) | |
| 68 | { | ||
| 69 | 12 | } | |
| 70 | |||
| 71 | 300 | message_base( | |
| 72 | detail::kind k, | ||
| 73 | core::string_view s) | ||
| 74 | : fields_view_base( | ||
| 75 | &this->fields_base::h_) | ||
| 76 | 300 | , fields_base(k, s) | |
| 77 | { | ||
| 78 | 298 | } | |
| 79 | |||
| 80 | 25 | message_base( | |
| 81 | detail::kind k, | ||
| 82 | char* storage, | ||
| 83 | std::size_t storage_size, | ||
| 84 | core::string_view s) | ||
| 85 | : fields_view_base( | ||
| 86 | &this->fields_base::h_) | ||
| 87 | , fields_base( | ||
| 88 | 25 | k, storage, storage_size, s) | |
| 89 | { | ||
| 90 | 25 | } | |
| 91 | |||
| 92 | explicit | ||
| 93 | 8 | message_base( | |
| 94 | detail::header const& ph) | ||
| 95 | : fields_view_base( | ||
| 96 | &this->fields_base::h_) | ||
| 97 | 8 | , fields_base(ph) | |
| 98 | { | ||
| 99 | 8 | } | |
| 100 | |||
| 101 | 8 | message_base( | |
| 102 | detail::header const& ph, | ||
| 103 | char* storage, | ||
| 104 | std::size_t storage_size) | ||
| 105 | : fields_view_base( | ||
| 106 | &this->fields_base::h_) | ||
| 107 | 8 | , fields_base(ph, storage, storage_size) | |
| 108 | { | ||
| 109 | 8 | } | |
| 110 | |||
| 111 | public: | ||
| 112 | //-------------------------------------------- | ||
| 113 | // | ||
| 114 | // Metadata | ||
| 115 | // | ||
| 116 | //-------------------------------------------- | ||
| 117 | |||
| 118 | /** Set the payload size | ||
| 119 | */ | ||
| 120 | BOOST_HTTP_PROTO_DECL | ||
| 121 | void | ||
| 122 | set_payload_size( | ||
| 123 | std::uint64_t n); | ||
| 124 | |||
| 125 | /** Set the Content-Length to the specified value | ||
| 126 | */ | ||
| 127 | BOOST_HTTP_PROTO_DECL | ||
| 128 | void | ||
| 129 | set_content_length( | ||
| 130 | std::uint64_t n); | ||
| 131 | |||
| 132 | /** Set whether the payload is chunked. | ||
| 133 | */ | ||
| 134 | BOOST_HTTP_PROTO_DECL | ||
| 135 | void | ||
| 136 | set_chunked(bool value); | ||
| 137 | |||
| 138 | /** Set whether the connection should stay open. | ||
| 139 | |||
| 140 | Even when keep-alive is set to true, the | ||
| 141 | semantics of the other header fields may | ||
| 142 | require the connection to be closed. For | ||
| 143 | example when there is no content length | ||
| 144 | specified in a response. | ||
| 145 | */ | ||
| 146 | BOOST_HTTP_PROTO_DECL | ||
| 147 | void | ||
| 148 | set_keep_alive(bool value); | ||
| 149 | }; | ||
| 150 | |||
| 151 | } // http_proto | ||
| 152 | } // boost | ||
| 153 | |||
| 154 | #endif | ||
| 155 |