status.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_HTTP_STATUS_HPP
  10. #define BOOST_BEAST_HTTP_STATUS_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <boost/beast/core/string.hpp>
  13. #include <iosfwd>
  14. namespace boost {
  15. namespace beast {
  16. namespace http {
  17. enum class status : unsigned
  18. {
  19. /** An unknown status-code.
  20. This value indicates that the value for the status code
  21. is not in the list of commonly recognized status codes.
  22. Callers interested in the exactly value should use the
  23. interface which provides the raw integer.
  24. */
  25. unknown = 0,
  26. continue_ = 100,
  27. /** Switching Protocols
  28. This status indicates that a request to switch to a new
  29. protocol was accepted and applied by the server. A successful
  30. response to a WebSocket Upgrade HTTP request will have this
  31. code.
  32. */
  33. switching_protocols = 101,
  34. processing = 102,
  35. ok = 200,
  36. created = 201,
  37. accepted = 202,
  38. non_authoritative_information = 203,
  39. no_content = 204,
  40. reset_content = 205,
  41. partial_content = 206,
  42. multi_status = 207,
  43. already_reported = 208,
  44. im_used = 226,
  45. multiple_choices = 300,
  46. moved_permanently = 301,
  47. found = 302,
  48. see_other = 303,
  49. not_modified = 304,
  50. use_proxy = 305,
  51. temporary_redirect = 307,
  52. permanent_redirect = 308,
  53. bad_request = 400,
  54. unauthorized = 401,
  55. payment_required = 402,
  56. forbidden = 403,
  57. not_found = 404,
  58. method_not_allowed = 405,
  59. not_acceptable = 406,
  60. proxy_authentication_required = 407,
  61. request_timeout = 408,
  62. conflict = 409,
  63. gone = 410,
  64. length_required = 411,
  65. precondition_failed = 412,
  66. payload_too_large = 413,
  67. uri_too_long = 414,
  68. unsupported_media_type = 415,
  69. range_not_satisfiable = 416,
  70. expectation_failed = 417,
  71. misdirected_request = 421,
  72. unprocessable_entity = 422,
  73. locked = 423,
  74. failed_dependency = 424,
  75. upgrade_required = 426,
  76. precondition_required = 428,
  77. too_many_requests = 429,
  78. request_header_fields_too_large = 431,
  79. connection_closed_without_response = 444,
  80. unavailable_for_legal_reasons = 451,
  81. client_closed_request = 499,
  82. internal_server_error = 500,
  83. not_implemented = 501,
  84. bad_gateway = 502,
  85. service_unavailable = 503,
  86. gateway_timeout = 504,
  87. http_version_not_supported = 505,
  88. variant_also_negotiates = 506,
  89. insufficient_storage = 507,
  90. loop_detected = 508,
  91. not_extended = 510,
  92. network_authentication_required = 511,
  93. network_connect_timeout_error = 599
  94. };
  95. /** Represents the class of a status-code.
  96. */
  97. enum class status_class : unsigned
  98. {
  99. /// Unknown status-class
  100. unknown = 0,
  101. /// The request was received, continuing processing.
  102. informational = 1,
  103. /// The request was successfully received, understood, and accepted.
  104. successful = 2,
  105. /// Further action needs to be taken in order to complete the request.
  106. redirection = 3,
  107. /// The request contains bad syntax or cannot be fulfilled.
  108. client_error = 4,
  109. /// The server failed to fulfill an apparently valid request.
  110. server_error = 5,
  111. };
  112. /** Converts the integer to a known status-code.
  113. If the integer does not match a known status code,
  114. @ref status::unknown is returned.
  115. */
  116. BOOST_BEAST_DECL
  117. status
  118. int_to_status(unsigned v);
  119. /** Convert an integer to a status_class.
  120. @param v The integer representing a status code.
  121. @return The status class. If the integer does not match
  122. a known status class, @ref status_class::unknown is returned.
  123. */
  124. BOOST_BEAST_DECL
  125. status_class
  126. to_status_class(unsigned v);
  127. /** Convert a status_code to a status_class.
  128. @param v The status code to convert.
  129. @return The status class.
  130. */
  131. BOOST_BEAST_DECL
  132. status_class
  133. to_status_class(status v);
  134. /** Returns the obsolete reason-phrase text for a status code.
  135. @param v The status code to use.
  136. */
  137. BOOST_BEAST_DECL
  138. string_view
  139. obsolete_reason(status v);
  140. /// Outputs the standard reason phrase of a status code to a stream.
  141. BOOST_BEAST_DECL
  142. std::ostream&
  143. operator<<(std::ostream&, status);
  144. } // http
  145. } // beast
  146. } // boost
  147. #ifdef BOOST_BEAST_HEADER_ONLY
  148. #include <boost/beast/http/impl/status.ipp>
  149. #endif
  150. #endif