File indexing completed on 2025-09-18 08:36:06
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_trivial<T>::value &&
0043 std::is_standard_layout<T>::value,
0044 "POD requirements not met");
0045
0046 public:
0047
0048
0049
0050
0051
0052 using value_type = span<T>;
0053
0054
0055
0056
0057
0058
0059
0060 static
0061 std::uint64_t
0062 size(value_type const& body)
0063 {
0064 return body.size();
0065 }
0066
0067
0068
0069
0070
0071 #if BOOST_BEAST_DOXYGEN
0072 using reader = __implementation_defined__;
0073 #else
0074 class reader
0075 {
0076 value_type& body_;
0077
0078 public:
0079 template<bool isRequest, class Fields>
0080 explicit
0081 reader(header<isRequest, Fields>&, value_type& b)
0082 : body_(b)
0083 {
0084 }
0085
0086 void
0087 init(boost::optional<
0088 std::uint64_t> const& length, error_code& ec)
0089 {
0090 if(length && *length > body_.size())
0091 {
0092 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0093 return;
0094 }
0095 ec = {};
0096 }
0097
0098 template<class ConstBufferSequence>
0099 std::size_t
0100 put(ConstBufferSequence const& buffers,
0101 error_code& ec)
0102 {
0103 auto const n = buffer_bytes(buffers);
0104 auto const len = body_.size();
0105 if(n > len)
0106 {
0107 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0108 return 0;
0109 }
0110 ec = {};
0111 net::buffer_copy(net::buffer(
0112 body_.data(), n), buffers);
0113 body_ = value_type{
0114 body_.data() + n, body_.size() - n};
0115 return n;
0116 }
0117
0118 void
0119 finish(error_code& ec)
0120 {
0121 ec = {};
0122 }
0123 };
0124 #endif
0125
0126
0127
0128
0129
0130 #if BOOST_BEAST_DOXYGEN
0131 using writer = __implementation_defined__;
0132 #else
0133 class writer
0134 {
0135 value_type const& body_;
0136
0137 public:
0138 using const_buffers_type =
0139 net::const_buffer;
0140
0141 template<bool isRequest, class Fields>
0142 explicit
0143 writer(header<isRequest, Fields> const&, value_type const& b)
0144 : body_(b)
0145 {
0146 }
0147
0148 void
0149 init(error_code& ec)
0150 {
0151 ec = {};
0152 }
0153
0154 boost::optional<std::pair<const_buffers_type, bool>>
0155 get(error_code& ec)
0156 {
0157 ec = {};
0158 return {{
0159 { body_.data(),
0160 body_.size() * sizeof(typename
0161 value_type::value_type)},
0162 false}};
0163 }
0164 };
0165 #endif
0166 };
0167
0168 }
0169 }
0170 }
0171
0172 #endif