reply.h 1.5 KB

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