1 // 2 // reply.hpp 3 // ~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // 10 11 #ifndef HTTP_REPLY_HPP 12 #define HTTP_REPLY_HPP 13 14 #include <string> 15 #include <vector> 16 #include <boost/asio.hpp> 17 #include "header.hpp" 18 19 namespace http { 20 namespace server { 21 22 /// A reply to be sent to a client. 23 struct reply 24 { 25 /// The status of the reply. 26 enum status_type 27 { 28 ok = 200, 29 created = 201, 30 accepted = 202, 31 no_content = 204, 32 multiple_choices = 300, 33 moved_permanently = 301, 34 moved_temporarily = 302, 35 not_modified = 304, 36 bad_request = 400, 37 unauthorized = 401, 38 forbidden = 403, 39 not_found = 404, 40 internal_server_error = 500, 41 not_implemented = 501, 42 bad_gateway = 502, 43 service_unavailable = 503 44 } status; 45 46 /// The headers to be included in the reply. 47 std::vector<header> headers; 48 49 /// The content to be sent in the reply. 50 std::string content; 51 52 /// Convert the reply into a vector of buffers. The buffers do not own the 53 /// underlying memory blocks, therefore the reply object must remain valid and 54 /// not be changed until the write operation has completed. 55 std::vector<boost::asio::const_buffer> to_buffers(); 56 57 /// Get a stock reply. 58 static reply stock_reply(status_type status); 59 }; 60 61 } // namespace server 62 } // namespace http 63 64 #endif // HTTP_REPLY_HPP 65