aboutsummaryrefslogtreecommitdiff
path: root/xs_http.h
diff options
context:
space:
mode:
authorgrunfink <grunfink@comam.es>2025-10-13 13:07:06 +0200
committergrunfink <grunfink@comam.es>2025-10-13 13:07:06 +0200
commit212284c792c86fca52e0172a4d097abc5bb45252 (patch)
tree4fe9ebc3859eec9edb46388a606cb6d54898c64a /xs_http.h
parent4f0b97ecf6ee157c56aa4fba781a8b6b5ea36174 (diff)
xs_http.h: new file.
Diffstat (limited to 'xs_http.h')
-rw-r--r--xs_http.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/xs_http.h b/xs_http.h
new file mode 100644
index 0000000..f2fd296
--- /dev/null
+++ b/xs_http.h
@@ -0,0 +1,42 @@
+/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
+
+#ifndef _XS_HTTP_H
+
+#define _XS_HTTP_H
+
+typedef enum {
+#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
+#include "xs_http_codes.h"
+#undef HTTP_STATUS
+} http_status;
+
+
+int xs_http_valid_status(int status);
+const char *xs_http_status_text(int status);
+
+
+#ifdef XS_IMPLEMENTATION
+
+int xs_http_valid_status(int status)
+/* is this HTTP status valid? */
+{
+ return status >= 200 && status <= 299;
+}
+
+
+const char *xs_http_status_text(int status)
+/* translate status codes to canonical status texts */
+{
+ switch (status) {
+ case 599: return "Timeout";
+#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
+#include "xs_http_codes.h"
+#undef HTTP_STATUS
+ default: return "Unknown";
+ }
+}
+
+
+#endif /* XS_IMPLEMENTATION */
+
+#endif /* XS_HTTP_H */