error.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // Copyright (c) 2016-2017 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_WEBSOCKET_ERROR_HPP
  10. #define BOOST_BEAST_WEBSOCKET_ERROR_HPP
  11. #include <boost/beast/websocket/detail/error.hpp>
  12. #include <boost/beast/core/detail/config.hpp>
  13. #include <boost/beast/core/error.hpp>
  14. namespace boost {
  15. namespace beast {
  16. namespace websocket {
  17. /// Error codes returned from @ref beast::websocket::stream operations.
  18. enum class error
  19. {
  20. /** The WebSocket stream was gracefully closed at both endpoints
  21. */
  22. closed = 1,
  23. /* The error codes error::failed and error::handshake_failed
  24. are no longer in use. Please change your code to compare values
  25. of type error_code against condition::handshake_failed
  26. and condition::protocol_violation instead.
  27. Apologies for the inconvenience.
  28. - VFALCO
  29. */
  30. #if ! BOOST_BEAST_DOXYGEN
  31. unused1 = 2, // failed
  32. unused2 = 3, // handshake_failed
  33. #endif
  34. /** The WebSocket operation caused a dynamic buffer overflow
  35. */
  36. buffer_overflow,
  37. /** The WebSocket stream produced an incomplete deflate block
  38. */
  39. partial_deflate_block,
  40. /** The WebSocket message exceeded the locally configured limit
  41. */
  42. message_too_big,
  43. //
  44. // Handshake failure errors
  45. //
  46. // These will compare equal to condition::handshake_failed
  47. //
  48. /** The WebSocket handshake was not HTTP/1.1
  49. Error codes with this value will compare equal to @ref condition::handshake_failed
  50. */
  51. bad_http_version,
  52. /** The WebSocket handshake method was not GET
  53. Error codes with this value will compare equal to @ref condition::handshake_failed
  54. */
  55. bad_method,
  56. /** The WebSocket handshake Host field is missing
  57. Error codes with this value will compare equal to @ref condition::handshake_failed
  58. */
  59. no_host,
  60. /** The WebSocket handshake Connection field is missing
  61. Error codes with this value will compare equal to @ref condition::handshake_failed
  62. */
  63. no_connection,
  64. /** The WebSocket handshake Connection field is missing the upgrade token
  65. Error codes with this value will compare equal to @ref condition::handshake_failed
  66. */
  67. no_connection_upgrade,
  68. /** The WebSocket handshake Upgrade field is missing
  69. Error codes with this value will compare equal to @ref condition::handshake_failed
  70. */
  71. no_upgrade,
  72. /** The WebSocket handshake Upgrade field is missing the websocket token
  73. Error codes with this value will compare equal to @ref condition::handshake_failed
  74. */
  75. no_upgrade_websocket,
  76. /** The WebSocket handshake Sec-WebSocket-Key field is missing
  77. Error codes with this value will compare equal to @ref condition::handshake_failed
  78. */
  79. no_sec_key,
  80. /** The WebSocket handshake Sec-WebSocket-Key field is invalid
  81. Error codes with this value will compare equal to @ref condition::handshake_failed
  82. */
  83. bad_sec_key,
  84. /** The WebSocket handshake Sec-WebSocket-Version field is missing
  85. Error codes with this value will compare equal to @ref condition::handshake_failed
  86. */
  87. no_sec_version,
  88. /** The WebSocket handshake Sec-WebSocket-Version field is invalid
  89. Error codes with this value will compare equal to @ref condition::handshake_failed
  90. */
  91. bad_sec_version,
  92. /** The WebSocket handshake Sec-WebSocket-Accept field is missing
  93. Error codes with this value will compare equal to @ref condition::handshake_failed
  94. */
  95. no_sec_accept,
  96. /** The WebSocket handshake Sec-WebSocket-Accept field is invalid
  97. Error codes with this value will compare equal to @ref condition::handshake_failed
  98. */
  99. bad_sec_accept,
  100. /** The WebSocket handshake was declined by the remote peer
  101. Error codes with this value will compare equal to @ref condition::handshake_failed
  102. */
  103. upgrade_declined,
  104. //
  105. // Protocol errors
  106. //
  107. // These will compare equal to condition::protocol_violation
  108. //
  109. /** The WebSocket frame contained an illegal opcode
  110. Error codes with this value will compare equal to @ref condition::protocol_violation
  111. */
  112. bad_opcode,
  113. /** The WebSocket data frame was unexpected
  114. Error codes with this value will compare equal to @ref condition::protocol_violation
  115. */
  116. bad_data_frame,
  117. /** The WebSocket continuation frame was unexpected
  118. Error codes with this value will compare equal to @ref condition::protocol_violation
  119. */
  120. bad_continuation,
  121. /** The WebSocket frame contained illegal reserved bits
  122. Error codes with this value will compare equal to @ref condition::protocol_violation
  123. */
  124. bad_reserved_bits,
  125. /** The WebSocket control frame was fragmented
  126. Error codes with this value will compare equal to @ref condition::protocol_violation
  127. */
  128. bad_control_fragment,
  129. /** The WebSocket control frame size was invalid
  130. Error codes with this value will compare equal to @ref condition::protocol_violation
  131. */
  132. bad_control_size,
  133. /** The WebSocket frame was unmasked
  134. Error codes with this value will compare equal to @ref condition::protocol_violation
  135. */
  136. bad_unmasked_frame,
  137. /** The WebSocket frame was masked
  138. Error codes with this value will compare equal to @ref condition::protocol_violation
  139. */
  140. bad_masked_frame,
  141. /** The WebSocket frame size was not canonical
  142. Error codes with this value will compare equal to @ref condition::protocol_violation
  143. */
  144. bad_size,
  145. /** The WebSocket frame payload was not valid utf8
  146. Error codes with this value will compare equal to @ref condition::protocol_violation
  147. */
  148. bad_frame_payload,
  149. /** The WebSocket close frame reason code was invalid
  150. Error codes with this value will compare equal to @ref condition::protocol_violation
  151. */
  152. bad_close_code,
  153. /** The WebSocket close frame payload size was invalid
  154. Error codes with this value will compare equal to @ref condition::protocol_violation
  155. */
  156. bad_close_size,
  157. /** The WebSocket close frame payload was not valid utf8
  158. Error codes with this value will compare equal to @ref condition::protocol_violation
  159. */
  160. bad_close_payload
  161. };
  162. /// Error conditions corresponding to sets of error codes.
  163. enum class condition
  164. {
  165. /** The WebSocket handshake failed
  166. This condition indicates that the WebSocket handshake failed. If
  167. the corresponding HTTP response indicates the keep-alive behavior,
  168. then the handshake may be reattempted.
  169. */
  170. handshake_failed = 1,
  171. /** A WebSocket protocol violation occurred
  172. This condition indicates that the remote peer on the WebSocket
  173. connection sent data which violated the protocol.
  174. */
  175. protocol_violation
  176. };
  177. } // websocket
  178. } // beast
  179. } // boost
  180. #include <boost/beast/websocket/impl/error.ipp>
  181. #endif