File indexing completed on 2025-01-18 09:29:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_HTTP_IMPL_BASIC_PARSER_HPP
0011 #define BOOST_BEAST_HTTP_IMPL_BASIC_PARSER_HPP
0012
0013 #include <boost/beast/core/buffer_traits.hpp>
0014 #include <boost/asio/buffer.hpp>
0015 #include <boost/make_unique.hpp>
0016
0017 namespace boost {
0018 namespace beast {
0019 namespace http {
0020
0021 template<bool isRequest>
0022 template<class ConstBufferSequence>
0023 std::size_t
0024 basic_parser<isRequest>::
0025 put(ConstBufferSequence const& buffers,
0026 error_code& ec)
0027 {
0028 static_assert(net::is_const_buffer_sequence<
0029 ConstBufferSequence>::value,
0030 "ConstBufferSequence type requirements not met");
0031 auto const p = net::buffer_sequence_begin(buffers);
0032 auto const last = net::buffer_sequence_end(buffers);
0033 if(p == last)
0034 {
0035 ec = {};
0036 return 0;
0037 }
0038 if(std::next(p) == last)
0039 {
0040
0041 return put(net::const_buffer(*p), ec);
0042 }
0043 auto const size = buffer_bytes(buffers);
0044 if(size <= max_stack_buffer)
0045 return put_from_stack(size, buffers, ec);
0046 if(size > buf_len_)
0047 {
0048
0049 buf_ = boost::make_unique_noinit<char[]>(size);
0050 buf_len_ = size;
0051 }
0052
0053 net::buffer_copy(net::buffer(
0054 buf_.get(), size), buffers);
0055 return put(net::const_buffer{
0056 buf_.get(), size}, ec);
0057 }
0058
0059 template<bool isRequest>
0060 boost::optional<std::uint64_t>
0061 basic_parser<isRequest>::
0062 content_length_unchecked() const
0063 {
0064 if(f_ & flagContentLength)
0065 return len0_;
0066 return boost::none;
0067 }
0068
0069 template<bool isRequest>
0070 template<class ConstBufferSequence>
0071 std::size_t
0072 basic_parser<isRequest>::
0073 put_from_stack(std::size_t size,
0074 ConstBufferSequence const& buffers,
0075 error_code& ec)
0076 {
0077 char buf[max_stack_buffer];
0078 net::buffer_copy(net::mutable_buffer(
0079 buf, sizeof(buf)), buffers);
0080 return put(net::const_buffer{
0081 buf, size}, ec);
0082 }
0083
0084 }
0085 }
0086 }
0087
0088 #endif