xs_http.h 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
  2. #ifndef _XS_HTTP_H
  3. #define _XS_HTTP_H
  4. typedef enum {
  5. #define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
  6. #include "xs_http_codes.h"
  7. #undef HTTP_STATUS
  8. } http_status;
  9. int xs_http_valid_status(int status);
  10. const char *xs_http_status_text(int status);
  11. #ifdef XS_IMPLEMENTATION
  12. int xs_http_valid_status(int status)
  13. /* is this HTTP status valid? */
  14. {
  15. return status >= 200 && status <= 299;
  16. }
  17. const char *xs_http_status_text(int status)
  18. /* translate status codes to canonical status texts */
  19. {
  20. switch (status) {
  21. case 599: return "Timeout";
  22. #define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
  23. #include "xs_http_codes.h"
  24. #undef HTTP_STATUS
  25. default: return "Unknown";
  26. }
  27. }
  28. #endif /* XS_IMPLEMENTATION */
  29. #endif /* XS_HTTP_H */