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