// // Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BEAST_HTTP_MESSAGE_HPP #define BEAST_HTTP_MESSAGE_HPP #include #include #include #include #include #include #include namespace beast { namespace http { namespace detail { struct request_fields { http::method_t method; std::string url; }; struct response_fields { int status; std::string reason; }; } // detail struct request_params { http::method_t method; std::string url; int version; }; struct response_params { int status; std::string reason; int version; }; /** A HTTP message. A message can be a request or response, depending on the `isRequest` template argument value. Requests and responses have different types, so functions may be overloaded on them if desired. The `Body` template argument type determines the model used to read or write the content body of the message. @tparam isRequest `true` if this is a request. @tparam Body A type meeting the requirements of Body. @tparam Headers A type meeting the requirements of Headers. */ template struct message : std::conditional_t { /** The trait type characterizing the body. The body member will be of type body_type::value_type. */ using body_type = Body; using headers_type = Headers; using is_request = std::integral_constant; int version; // 10 or 11 headers_type headers; typename Body::value_type body; message(); message(message&&) = default; message(message const&) = default; message& operator=(message&&) = default; message& operator=(message const&) = default; /** Construct a HTTP request. */ explicit message(request_params params); /** Construct a HTTP response. */ explicit message(response_params params); /// Serialize the request or response line to a Streambuf. template void write_firstline(Streambuf& streambuf) const { write_firstline(streambuf, std::integral_constant{}); } /// Diagnostics only template friend std::ostream& operator<<(std::ostream& os, message const& m); private: template void write_firstline(Streambuf& streambuf, std::true_type) const; template void write_firstline(Streambuf& streambuf, std::false_type) const; }; #if ! GENERATING_DOCS /// A typical HTTP request template>> using request = message; /// A typical HTTP response template>> using response = message; #endif // For diagnostic output only template std::ostream& operator<<(std::ostream& os, message const& m); /// Write a FieldSequence to a Streambuf. template void write_fields(Streambuf& streambuf, FieldSequence const& fields); /// Returns `true` if a message indicates a keep alive template bool is_keep_alive(message const& msg); /// Returns `true` if a message indicates a HTTP Upgrade request or response template bool is_upgrade(message const& msg); } // http } // beast #include #endif