File: xs_http.h

package info (click to toggle)
snac2 2.85-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,732 kB
  • sloc: ansic: 21,478; sh: 179; makefile: 69; python: 34
file content (42 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 */