Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:32

0001 //
0002 // Copyright (c) 2022 Seth Heeren (sgheeren at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 #ifndef BOOST_BEAST_HTTP_MESSAGE_GENERATOR_HPP
0010 #define BOOST_BEAST_HTTP_MESSAGE_GENERATOR_HPP
0011 
0012 #include <boost/beast/core/span.hpp>
0013 #include <boost/beast/http/message.hpp>
0014 #include <boost/beast/http/serializer.hpp>
0015 #include <memory>
0016 
0017 namespace boost {
0018 namespace beast {
0019 namespace http {
0020 
0021 /** Type-erased buffers generator for @ref http::message
0022    
0023     Implements the BuffersGenerator concept for any concrete instance of the
0024     @ref http::message template.
0025    
0026     @ref http::message_generator takes ownership of a message on construction,
0027     erasing the concrete type from the interface.
0028    
0029     This makes it practical for use in server applications to implement request
0030     handling:
0031    
0032     @code
0033     template <class Body, class Fields>
0034     http::message_generator handle_request(
0035         string_view doc_root,
0036         http::request<Body, Fields>&& request);
0037     @endcode
0038    
0039     The @ref beast::write and @ref beast::async_write operations are provided
0040     for BuffersGenerator. The @ref http::message::keep_alive property is made
0041     available for use after writing the message.
0042 */
0043 class message_generator
0044 {
0045 public:
0046     using const_buffers_type = span<net::const_buffer>;
0047 
0048     template <bool isRequest, class Body, class Fields>
0049     message_generator(http::message<isRequest, Body, Fields>&&);
0050 
0051     /// `BuffersGenerator`
0052     bool is_done() const {
0053         return impl_->is_done();
0054     }
0055 
0056     /// `BuffersGenerator`
0057     const_buffers_type
0058     prepare(error_code& ec)
0059     {
0060         return impl_->prepare(ec);
0061     }
0062 
0063     /// `BuffersGenerator`
0064     void
0065     consume(std::size_t n)
0066     {
0067         impl_->consume(n);
0068     }
0069 
0070     /// Returns the result of `m.keep_alive()` on the underlying message
0071     bool
0072     keep_alive() const noexcept
0073     {
0074         return impl_->keep_alive();
0075     }
0076 
0077 private:
0078     struct impl_base
0079     {
0080         virtual ~impl_base() = default;
0081         virtual bool is_done() = 0;
0082         virtual const_buffers_type prepare(error_code& ec) = 0;
0083         virtual void consume(std::size_t n) = 0;
0084         virtual bool keep_alive() const noexcept = 0;
0085     };
0086 
0087     std::unique_ptr<impl_base> impl_;
0088 
0089     template <bool isRequest, class Body, class Fields>
0090     struct generator_impl;
0091 };
0092 
0093 } // namespace http
0094 } // namespace beast
0095 } // namespace boost
0096 
0097 #include <boost/beast/http/impl/message_generator.hpp>
0098 
0099 #endif