File indexing completed on 2026-08-16 08:38:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_HTTP_SPAN_BODY_HPP
0011 #define BOOST_BEAST_HTTP_SPAN_BODY_HPP
0012
0013 #include <boost/beast/http/span_body_fwd.hpp>
0014
0015 #include <boost/beast/core/buffer_traits.hpp>
0016 #include <boost/beast/core/detail/config.hpp>
0017 #include <boost/beast/core/span.hpp>
0018 #include <boost/beast/http/error.hpp>
0019 #include <boost/beast/http/message.hpp>
0020 #include <boost/optional.hpp>
0021
0022 namespace boost {
0023 namespace beast {
0024 namespace http {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 template<class T>
0038 struct span_body
0039 {
0040 private:
0041 static_assert(
0042 std::is_trivially_default_constructible<T>::value &&
0043 std::is_trivially_copyable<T>::value &&
0044 std::is_standard_layout<T>::value,
0045 "POD requirements not met");
0046
0047 public:
0048
0049
0050
0051
0052
0053 using value_type = span<T>;
0054
0055
0056
0057
0058
0059
0060
0061 static
0062 std::uint64_t
0063 size(value_type const& body)
0064 {
0065 return body.size();
0066 }
0067
0068
0069
0070
0071
0072 #if BOOST_BEAST_DOXYGEN
0073 using reader = __implementation_defined__;
0074 #else
0075 class reader
0076 {
0077 value_type& body_;
0078
0079 public:
0080 template<bool isRequest, class Fields>
0081 explicit
0082 reader(header<isRequest, Fields>&, value_type& b)
0083 : body_(b)
0084 {
0085 }
0086
0087 void
0088 init(boost::optional<
0089 std::uint64_t> const& length, error_code& ec)
0090 {
0091 if(length && *length > body_.size())
0092 {
0093 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0094 return;
0095 }
0096 ec = {};
0097 }
0098
0099 template<class ConstBufferSequence>
0100 std::size_t
0101 put(ConstBufferSequence const& buffers,
0102 error_code& ec)
0103 {
0104 auto const n = buffer_bytes(buffers);
0105 auto const len = body_.size();
0106 if(n > len)
0107 {
0108 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0109 return 0;
0110 }
0111 ec = {};
0112 net::buffer_copy(net::buffer(
0113 body_.data(), n), buffers);
0114 body_ = value_type{
0115 body_.data() + n, body_.size() - n};
0116 return n;
0117 }
0118
0119 void
0120 finish(error_code& ec)
0121 {
0122 ec = {};
0123 }
0124 };
0125 #endif
0126
0127
0128
0129
0130
0131 #if BOOST_BEAST_DOXYGEN
0132 using writer = __implementation_defined__;
0133 #else
0134 class writer
0135 {
0136 value_type const& body_;
0137
0138 public:
0139 using const_buffers_type =
0140 net::const_buffer;
0141
0142 template<bool isRequest, class Fields>
0143 explicit
0144 writer(header<isRequest, Fields> const&, value_type const& b)
0145 : body_(b)
0146 {
0147 }
0148
0149 void
0150 init(error_code& ec)
0151 {
0152 ec = {};
0153 }
0154
0155 boost::optional<std::pair<const_buffers_type, bool>>
0156 get(error_code& ec)
0157 {
0158 ec = {};
0159 return {{
0160 { body_.data(),
0161 body_.size() * sizeof(typename
0162 value_type::value_type)},
0163 false}};
0164 }
0165 };
0166 #endif
0167 };
0168
0169 }
0170 }
0171 }
0172
0173 #endif