| 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 | /** Mixin for modifing common metadata | ||
| 23 | in HTTP request and response messages. | ||
| 24 | |||
| 25 | This type is useful for modifying common | ||
| 26 | properties shared by both requests | ||
| 27 | and responses. | ||
| 28 | |||
| 29 | @see | ||
| 30 | @ref message_view_base, | ||
| 31 | @ref response, | ||
| 32 | @ref request, | ||
| 33 | @ref static_response, | ||
| 34 | @ref static_request, | ||
| 35 | @ref metadata. | ||
| 36 | */ | ||
| 37 | class message_base | ||
| 38 | : public fields_base | ||
| 39 | , public message_view_base | ||
| 40 | { | ||
| 41 | friend class request_base; | ||
| 42 | friend class response_base; | ||
| 43 | |||
| 44 | explicit | ||
| 45 | 159 | message_base( | |
| 46 | detail::kind k) noexcept | ||
| 47 | : fields_view_base( | ||
| 48 | &this->fields_base::h_) | ||
| 49 | 159 | , fields_base(k) | |
| 50 | { | ||
| 51 | 159 | } | |
| 52 | |||
| 53 | 40 | message_base( | |
| 54 | detail::kind k, | ||
| 55 | char* storage, | ||
| 56 | std::size_t cap) noexcept | ||
| 57 | : fields_view_base(&this->fields_base::h_) | ||
| 58 | , fields_base( | ||
| 59 | 40 | k, storage, cap) | |
| 60 | { | ||
| 61 | 40 | } | |
| 62 | |||
| 63 | 304 | message_base( | |
| 64 | detail::kind k, | ||
| 65 | core::string_view s) | ||
| 66 | : fields_view_base( | ||
| 67 | &this->fields_base::h_) | ||
| 68 | 304 | , fields_base(k, s) | |
| 69 | { | ||
| 70 | 302 | } | |
| 71 | |||
| 72 | 25 | message_base( | |
| 73 | detail::kind k, | ||
| 74 | char* storage, | ||
| 75 | std::size_t cap, | ||
| 76 | core::string_view s) | ||
| 77 | : fields_view_base( | ||
| 78 | &this->fields_base::h_) | ||
| 79 | , fields_base( | ||
| 80 | 25 | k, storage, cap, s) | |
| 81 | { | ||
| 82 | 25 | } | |
| 83 | |||
| 84 | explicit | ||
| 85 | 8 | message_base( | |
| 86 | detail::header const& ph) | ||
| 87 | : fields_view_base( | ||
| 88 | &this->fields_base::h_) | ||
| 89 | 8 | , fields_base(ph) | |
| 90 | { | ||
| 91 | 8 | } | |
| 92 | |||
| 93 | 8 | message_base( | |
| 94 | detail::header const& ph, | ||
| 95 | char* storage, | ||
| 96 | std::size_t cap) | ||
| 97 | : fields_view_base( | ||
| 98 | &this->fields_base::h_) | ||
| 99 | 8 | , fields_base(ph, storage, cap) | |
| 100 | { | ||
| 101 | 8 | } | |
| 102 | |||
| 103 | public: | ||
| 104 | //-------------------------------------------- | ||
| 105 | // | ||
| 106 | // Metadata | ||
| 107 | // | ||
| 108 | //-------------------------------------------- | ||
| 109 | |||
| 110 | /** Set the payload size. | ||
| 111 | |||
| 112 | @par Exception Safety | ||
| 113 | Strong guarantee. | ||
| 114 | Calls to allocate may throw. | ||
| 115 | Exception thrown if max capacity exceeded. | ||
| 116 | |||
| 117 | @throw std::length_error | ||
| 118 | Max capacity would be exceeded. | ||
| 119 | |||
| 120 | @param n The payload size to set. | ||
| 121 | */ | ||
| 122 | BOOST_HTTP_PROTO_DECL | ||
| 123 | void | ||
| 124 | set_payload_size( | ||
| 125 | std::uint64_t n); | ||
| 126 | |||
| 127 | /** Set the Content-Length to the specified value. | ||
| 128 | |||
| 129 | @par Exception Safety | ||
| 130 | Strong guarantee. | ||
| 131 | Calls to allocate may throw. | ||
| 132 | Exception thrown if max capacity exceeded. | ||
| 133 | |||
| 134 | @throw std::length_error | ||
| 135 | Max capacity would be exceeded. | ||
| 136 | |||
| 137 | @param n The Content-Length to set. | ||
| 138 | */ | ||
| 139 | BOOST_HTTP_PROTO_DECL | ||
| 140 | void | ||
| 141 | set_content_length( | ||
| 142 | std::uint64_t n); | ||
| 143 | |||
| 144 | /** Set whether the payload is chunked. | ||
| 145 | |||
| 146 | @par Exception Safety | ||
| 147 | Strong guarantee. | ||
| 148 | Calls to allocate may throw. | ||
| 149 | Exception thrown if max capacity exceeded. | ||
| 150 | |||
| 151 | @throw std::length_error | ||
| 152 | Max capacity would be exceeded. | ||
| 153 | |||
| 154 | @param value The value to set. | ||
| 155 | */ | ||
| 156 | BOOST_HTTP_PROTO_DECL | ||
| 157 | void | ||
| 158 | set_chunked(bool value); | ||
| 159 | |||
| 160 | /** Set whether the connection should stay open. | ||
| 161 | |||
| 162 | Even when keep-alive is set to true, the | ||
| 163 | semantics of the other header fields may | ||
| 164 | require the connection to be closed. For | ||
| 165 | example when there is no content length | ||
| 166 | specified in a response. | ||
| 167 | |||
| 168 | @par Exception Safety | ||
| 169 | Strong guarantee. | ||
| 170 | Calls to allocate may throw. | ||
| 171 | Exception thrown if max capacity exceeded. | ||
| 172 | |||
| 173 | @throw std::length_error | ||
| 174 | Max capacity would be exceeded. | ||
| 175 | |||
| 176 | @param value The value to set. | ||
| 177 | */ | ||
| 178 | BOOST_HTTP_PROTO_DECL | ||
| 179 | void | ||
| 180 | set_keep_alive(bool value); | ||
| 181 | }; | ||
| 182 | |||
| 183 | } // http_proto | ||
| 184 | } // boost | ||
| 185 | |||
| 186 | #endif | ||
| 187 |