error.ipp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_IMPL_ERROR_IPP
  10. #define BOOST_BEAST_HTTP_IMPL_ERROR_IPP
  11. #include <boost/beast/http/error.hpp>
  12. #include <type_traits>
  13. namespace boost {
  14. namespace beast {
  15. namespace http {
  16. namespace detail {
  17. class http_error_category : public error_category
  18. {
  19. public:
  20. const char*
  21. name() const noexcept override
  22. {
  23. return "beast.http";
  24. }
  25. http_error_category() : error_category(0x964627da815bf210u) {}
  26. BOOST_BEAST_DECL
  27. char const*
  28. message(int ev, char*, std::size_t) const noexcept override
  29. {
  30. switch(static_cast<error>(ev))
  31. {
  32. case error::end_of_stream: return "end of stream";
  33. case error::partial_message: return "partial message";
  34. case error::need_more: return "need more";
  35. case error::unexpected_body: return "unexpected body";
  36. case error::need_buffer: return "need buffer";
  37. case error::end_of_chunk: return "end of chunk";
  38. case error::buffer_overflow: return "buffer overflow";
  39. case error::header_limit: return "header limit exceeded";
  40. case error::body_limit: return "body limit exceeded";
  41. case error::bad_alloc: return "bad alloc";
  42. case error::bad_line_ending: return "bad line ending";
  43. case error::bad_method: return "bad method";
  44. case error::bad_target: return "bad target";
  45. case error::bad_version: return "bad version";
  46. case error::bad_status: return "bad status";
  47. case error::bad_reason: return "bad reason";
  48. case error::bad_field: return "bad field";
  49. case error::bad_value: return "bad value";
  50. case error::bad_content_length: return "bad Content-Length";
  51. case error::bad_transfer_encoding: return "bad Transfer-Encoding";
  52. case error::bad_chunk: return "bad chunk";
  53. case error::bad_chunk_extension: return "bad chunk extension";
  54. case error::bad_obs_fold: return "bad obs-fold";
  55. case error::multiple_content_length: return "multiple Content-Length";
  56. case error::stale_parser: return "stale parser";
  57. case error::short_read: return "unexpected eof in body";
  58. default:
  59. return "beast.http error";
  60. }
  61. }
  62. std::string
  63. message(int ev) const override
  64. {
  65. return message(ev, nullptr, 0);
  66. }
  67. error_condition
  68. default_error_condition(
  69. int ev) const noexcept override
  70. {
  71. return error_condition{ev, *this};
  72. }
  73. bool
  74. equivalent(int ev,
  75. error_condition const& condition
  76. ) const noexcept override
  77. {
  78. return condition.value() == ev &&
  79. &condition.category() == this;
  80. }
  81. bool
  82. equivalent(error_code const& error,
  83. int ev) const noexcept override
  84. {
  85. return error.value() == ev &&
  86. &error.category() == this;
  87. }
  88. };
  89. } // detail
  90. error_code
  91. make_error_code(error ev)
  92. {
  93. static detail::http_error_category const cat{};
  94. return error_code{static_cast<
  95. std::underlying_type<error>::type>(ev), cat};
  96. }
  97. } // http
  98. } // beast
  99. } // boost
  100. #endif