error.hpp 7.1 KB

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