2.87 xs_http.h
 1/* copyright (c) 2022 - 2026 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 */