httpcodes.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. enum HttpCodes {
  4. HTTP_CONTINUE = 100,
  5. HTTP_SWITCHING_PROTOCOLS = 101,
  6. HTTP_PROCESSING = 102,
  7. HTTP_EARLY_HINTS = 103,
  8. HTTP_OK = 200,
  9. HTTP_CREATED = 201,
  10. HTTP_ACCEPTED = 202,
  11. HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
  12. HTTP_NO_CONTENT = 204,
  13. HTTP_RESET_CONTENT = 205,
  14. HTTP_PARTIAL_CONTENT = 206,
  15. HTTP_MULTI_STATUS = 207,
  16. HTTP_ALREADY_REPORTED = 208,
  17. HTTP_IM_USED = 226,
  18. HTTP_MULTIPLE_CHOICES = 300,
  19. HTTP_MOVED_PERMANENTLY = 301,
  20. HTTP_FOUND = 302,
  21. HTTP_SEE_OTHER = 303,
  22. HTTP_NOT_MODIFIED = 304,
  23. HTTP_USE_PROXY = 305,
  24. HTTP_TEMPORARY_REDIRECT = 307,
  25. HTTP_PERMANENT_REDIRECT = 308,
  26. HTTP_BAD_REQUEST = 400,
  27. HTTP_UNAUTHORIZED = 401,
  28. HTTP_PAYMENT_REQUIRED = 402,
  29. HTTP_FORBIDDEN = 403,
  30. HTTP_NOT_FOUND = 404,
  31. HTTP_METHOD_NOT_ALLOWED = 405,
  32. HTTP_NOT_ACCEPTABLE = 406,
  33. HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
  34. HTTP_REQUEST_TIME_OUT = 408,
  35. HTTP_CONFLICT = 409,
  36. HTTP_GONE = 410,
  37. HTTP_LENGTH_REQUIRED = 411,
  38. HTTP_PRECONDITION_FAILED = 412,
  39. HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
  40. HTTP_REQUEST_URI_TOO_LARGE = 414,
  41. HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
  42. HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
  43. HTTP_EXPECTATION_FAILED = 417,
  44. HTTP_I_AM_A_TEAPOT = 418,
  45. HTTP_AUTHENTICATION_TIMEOUT = 419,
  46. HTTP_MISDIRECTED_REQUEST = 421,
  47. HTTP_UNPROCESSABLE_ENTITY = 422,
  48. HTTP_LOCKED = 423,
  49. HTTP_FAILED_DEPENDENCY = 424,
  50. HTTP_UNORDERED_COLLECTION = 425,
  51. HTTP_UPGRADE_REQUIRED = 426,
  52. HTTP_PRECONDITION_REQUIRED = 428,
  53. HTTP_TOO_MANY_REQUESTS = 429,
  54. HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
  55. HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
  56. HTTP_INTERNAL_SERVER_ERROR = 500,
  57. HTTP_NOT_IMPLEMENTED = 501,
  58. HTTP_BAD_GATEWAY = 502,
  59. HTTP_SERVICE_UNAVAILABLE = 503,
  60. HTTP_GATEWAY_TIME_OUT = 504,
  61. HTTP_HTTP_VERSION_NOT_SUPPORTED = 505,
  62. HTTP_VARIANT_ALSO_NEGOTIATES = 506,
  63. HTTP_INSUFFICIENT_STORAGE = 507,
  64. HTTP_LOOP_DETECTED = 508,
  65. HTTP_BANDWIDTH_LIMIT_EXCEEDED = 509,
  66. HTTP_NOT_EXTENDED = 510,
  67. HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
  68. HTTP_UNASSIGNED_512 = 512,
  69. HTTP_CODE_MAX
  70. };
  71. TStringBuf HttpCodeStrEx(int code) noexcept;
  72. inline TStringBuf HttpCodeStr(int code) noexcept {
  73. return HttpCodeStrEx(code).Skip(4);
  74. }
  75. inline bool IsHttpCode(int code) noexcept {
  76. return HttpCodeStrEx(code).data() != HttpCodeStrEx(0).data();
  77. }
  78. inline bool IsUserError(int code) noexcept {
  79. return code >= 400 && code < 500;
  80. }
  81. inline bool IsServerError(int code) noexcept {
  82. return code >= 500;
  83. }