main 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
 7#include "xs.h"
 8
 9typedef enum {
10#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
11#include "xs_http_codes.h"
12#undef HTTP_STATUS
13} http_status;
14
15
16int xs_http_valid_status(int status);
17const char *xs_http_status_text(int status);
18
19
20#ifdef XS_IMPLEMENTATION
21
22int xs_http_valid_status(int status)
23/* is this HTTP status valid? */
24{
25    return status >= 200 && status <= 299;
26}
27
28
29const char *xs_http_status_text(int status)
30/* translate status codes to canonical status texts */
31{
32    switch (status) {
33        case 599: return "Timeout";
34#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
35#include "xs_http_codes.h"
36#undef HTTP_STATUS
37        default: return "Unknown";
38    }
39}
40
41
42#endif /* XS_IMPLEMENTATION */
43
44#endif /* XS_HTTP_H */