reply.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // reply.hpp
  3. // ~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. #ifndef HTTP_REPLY_HPP
  11. #define HTTP_REPLY_HPP
  12. #include <string>
  13. #include <vector>
  14. #include <boost/asio.hpp>
  15. #include "header.hpp"
  16. namespace http {
  17. namespace server {
  18. /// A reply to be sent to a client.
  19. struct reply
  20. {
  21. /// The status of the reply.
  22. enum status_type
  23. {
  24. ok = 200,
  25. created = 201,
  26. accepted = 202,
  27. no_content = 204,
  28. multiple_choices = 300,
  29. moved_permanently = 301,
  30. moved_temporarily = 302,
  31. not_modified = 304,
  32. bad_request = 400,
  33. unauthorized = 401,
  34. forbidden = 403,
  35. not_found = 404,
  36. internal_server_error = 500,
  37. not_implemented = 501,
  38. bad_gateway = 502,
  39. service_unavailable = 503
  40. } status;
  41. /// The headers to be included in the reply.
  42. std::vector<header> headers;
  43. /// The content to be sent in the reply.
  44. std::string content;
  45. /// Convert the reply into a vector of buffers. The buffers do not own the
  46. /// underlying memory blocks, therefore the reply object must remain valid and
  47. /// not be changed until the write operation has completed.
  48. std::vector<boost::asio::const_buffer> to_buffers();
  49. /// Get a stock reply.
  50. static reply stock_reply(status_type status);
  51. };
  52. } // namespace server
  53. } // namespace http
  54. #endif // HTTP_REPLY_HPP