// // 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 namespace beast { namespace http { namespace detail { struct request_fields { std::string method; std::string url; protected: void swap(request_fields& other) { using std::swap; swap(method, other.method); swap(url, other.url); } }; struct response_fields { int status; std::string reason; protected: void swap(response_fields& other) { using std::swap; swap(status, other.status); swap(reason, other.reason); } }; } // detail /** 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::type { /** The type controlling the body traits. The body member will be of type `body_type::value_type`. */ using body_type = Body; /// The type representing the headers. using headers_type = Headers; /// Indicates if the message is a request. using is_request = std::integral_constant; /// The container holding the headers. headers_type headers; /// A container representing the body. typename Body::value_type body; /// Default constructor message() = default; /** Construct a message. @param u An argument forwarded to the body constructor. */ template explicit message(U&& u) : body(std::forward(u)) { } /** Construct a message. @param u An argument forwarded to the body constructor. @param v An argument forwarded to the headers constructor. */ template message(U&& u, V&& v) : headers(std::forward(v)) , body(std::forward(u)) { } /** Construct a message. @param un A tuple forwarded as a parameter pack to the body constructor. */ template message(std::piecewise_construct_t, std::tuple un) : message(std::piecewise_construct, un, beast::detail::make_index_sequence{}) { } /** Construct a message. @param un A tuple forwarded as a parameter pack to the body constructor. @param vn A tuple forwarded as a parameter pack to the headers constructor. */ template message(std::piecewise_construct_t, std::tuple&& un, std::tuple&& vn) : message(std::piecewise_construct, un, vn, beast::detail::make_index_sequence{}, beast::detail::make_index_sequence{}) { } /// Swap this message for another message. void swap(message& other); private: using base = typename std::conditional::type; template message(std::piecewise_construct_t, std::tuple& tu, beast::detail::index_sequence) : body(std::forward(std::get(tu))...) { } template message(std::piecewise_construct_t, std::tuple& tu, std::tuple& tv, beast::detail::index_sequence, beast::detail::index_sequence) : headers(std::forward(std::get(tv))...) , body(std::forward(std::get(tu))...) { } }; template void message:: swap(message& other) { using std::swap; base::swap(other); swap(headers, other.headers); swap(body, other.body); } /// Swap one message for another message. template inline void swap(message& lhs, message& rhs) { lhs.swap(rhs); } /// A typical HTTP request template>> using request = message; /// A typical HTTP response template>> using response = message; } // http } // beast #endif