summaryrefslogtreecommitdiff
path: root/xs_http.h
diff options
context:
space:
mode:
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 @@
1/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
2
3#ifndef _XS_HTTP_H
4
5#define _XS_HTTP_H
6
7typedef enum {
8#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
9#include "xs_http_codes.h"
10#undef HTTP_STATUS
11} http_status;
12
13
14int xs_http_valid_status(int status);
15const char *xs_http_status_text(int status);
16
17
18#ifdef XS_IMPLEMENTATION
19
20int xs_http_valid_status(int status)
21/* is this HTTP status valid? */
22{
23 return status >= 200 && status <= 299;
24}
25
26
27const char *xs_http_status_text(int status)
28/* translate status codes to canonical status texts */
29{
30 switch (status) {
31 case 599: return "Timeout";
32#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
33#include "xs_http_codes.h"
34#undef HTTP_STATUS
35 default: return "Unknown";
36 }
37}
38
39
40#endif /* XS_IMPLEMENTATION */
41
42#endif /* XS_HTTP_H */