File indexing completed on 2025-01-18 09:29:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_HTTP_VECTOR_BODY_HPP
0011 #define BOOST_BEAST_HTTP_VECTOR_BODY_HPP
0012
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/core/buffer_traits.hpp>
0015 #include <boost/beast/http/error.hpp>
0016 #include <boost/beast/http/message.hpp>
0017 #include <boost/beast/core/detail/clamp.hpp>
0018 #include <boost/asio/buffer.hpp>
0019 #include <boost/optional.hpp>
0020 #include <cstdint>
0021 #include <limits>
0022 #include <memory>
0023 #include <stdexcept>
0024 #include <string>
0025 #include <utility>
0026
0027 namespace boost {
0028 namespace beast {
0029 namespace http {
0030
0031
0032
0033
0034
0035
0036
0037 template<class T, class Allocator = std::allocator<T>>
0038 struct vector_body
0039 {
0040 private:
0041 static_assert(sizeof(T) == 1,
0042 "T requirements not met");
0043
0044 public:
0045
0046
0047
0048
0049
0050 using value_type = std::vector<T, Allocator>;
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)
0089 {
0090 if(*length > body_.max_size())
0091 {
0092 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0093 return;
0094 }
0095 body_.reserve(beast::detail::clamp(*length));
0096 }
0097 ec = {};
0098 }
0099
0100 template<class ConstBufferSequence>
0101 std::size_t
0102 put(ConstBufferSequence const& buffers,
0103 error_code& ec)
0104 {
0105 auto const n = buffer_bytes(buffers);
0106 auto const len = body_.size();
0107 if (n > body_.max_size() - len)
0108 {
0109 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0110 return 0;
0111 }
0112
0113 body_.resize(len + n);
0114 ec = {};
0115 return net::buffer_copy(net::buffer(
0116 &body_[0] + len, n), buffers);
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 {{const_buffers_type{
0160 body_.data(), body_.size()}, false}};
0161 }
0162 };
0163 #endif
0164 };
0165
0166 }
0167 }
0168 }
0169
0170 #endif