qhttpabstracts.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "qhttpabstracts.hpp"
  2. #include "http-parser/http_parser.h"
  3. ///////////////////////////////////////////////////////////////////////////////
  4. namespace qhttp {
  5. ///////////////////////////////////////////////////////////////////////////////
  6. #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
  7. # error "to compile QHttp classes, Qt 5.0 or later is needed."
  8. #endif
  9. #define HTTP_STATUS_MAP(XX) \
  10. XX(100, "Continue") \
  11. XX(101, "Switching Protocols") \
  12. /* RFC 2518) obsoleted by RFC 4918 */ \
  13. XX(102, "Processing") \
  14. XX(200, "OK") \
  15. XX(201, "Created") \
  16. XX(202, "Accepted") \
  17. XX(203, "Non-Authoritative Information") \
  18. XX(204, "No Content") \
  19. XX(205, "Reset Content") \
  20. XX(206, "Partial Content") \
  21. /* RFC 4918 */ \
  22. XX(207, "Multi-Status") \
  23. XX(300, "Multiple Choices") \
  24. XX(301, "Moved Permanently") \
  25. XX(302, "Moved Temporarily") \
  26. XX(303, "See Other") \
  27. XX(304, "Not Modified") \
  28. XX(305, "Use Proxy") \
  29. XX(307, "Temporary Redirect") \
  30. XX(400, "Bad Request") \
  31. XX(401, "Unauthorized") \
  32. XX(402, "Payment Required") \
  33. XX(403, "Forbidden") \
  34. XX(404, "Not Found") \
  35. XX(405, "Method Not Allowed") \
  36. XX(406, "Not Acceptable") \
  37. XX(407, "Proxy Authentication Required") \
  38. XX(408, "Request Time-out") \
  39. XX(409, "Conflict") \
  40. XX(410, "Gone") \
  41. XX(411, "Length Required") \
  42. XX(412, "Precondition Failed") \
  43. XX(413, "Request Entity Too Large") \
  44. XX(414, "Request-URI Too Large") \
  45. XX(415, "Unsupported Media Type") \
  46. XX(416, "Requested Range Not Satisfiable") \
  47. XX(417, "Expectation Failed") \
  48. /* RFC 2324 */ \
  49. XX(418, "I\"m a teapot") \
  50. /* RFC 4918 */ \
  51. XX(422, "Unprocessable Entity") \
  52. /* RFC 4918 */ \
  53. XX(423, "Locked") \
  54. /* RFC 4918 */ \
  55. XX(424, "Failed Dependency") \
  56. /* RFC 4918 */ \
  57. XX(425, "Unordered Collection") \
  58. /* RFC 2817 */ \
  59. XX(426, "Upgrade Required") \
  60. XX(500, "Internal Server Error") \
  61. XX(501, "Not Implemented") \
  62. XX(502, "Bad Gateway") \
  63. XX(503, "Service Unavailable") \
  64. XX(504, "Gateway Time-out") \
  65. XX(505, "HTTP Version not supported") \
  66. /* RFC 2295 */ \
  67. XX(506, "Variant Also Negotiates") \
  68. /* RFC 4918 */ \
  69. XX(507, "Insufficient Storage") \
  70. XX(509, "Bandwidth Limit Exceeded") \
  71. /* RFC 2774 */ \
  72. XX(510, "Not Extended")
  73. #define PATCH_STATUS_CODES(n,s) {n, s},
  74. static struct {
  75. int code;
  76. const char* message;
  77. } g_status_codes[] {
  78. HTTP_STATUS_MAP(PATCH_STATUS_CODES)
  79. };
  80. #undef PATCH_STATUS_CODES
  81. ///////////////////////////////////////////////////////////////////////////////
  82. const char*
  83. Stringify::toString(TStatusCode code) {
  84. size_t count = sizeof(g_status_codes) / sizeof(g_status_codes[0]);
  85. for ( size_t i = 0; i < count; i++ ) {
  86. if ( g_status_codes[i].code == code )
  87. return g_status_codes[i].message;
  88. }
  89. return nullptr;
  90. }
  91. const char*
  92. Stringify::toString(THttpMethod method) {
  93. return http_method_str(static_cast<http_method>(method));
  94. }
  95. ///////////////////////////////////////////////////////////////////////////////
  96. QHttpAbstractInput::QHttpAbstractInput(QObject* parent) : QObject(parent) {
  97. }
  98. QHttpAbstractOutput::QHttpAbstractOutput(QObject *parent) : QObject(parent) {
  99. }
  100. ///////////////////////////////////////////////////////////////////////////////
  101. } // namespace qhttp
  102. ///////////////////////////////////////////////////////////////////////////////