1#ifndef HTTP_H
2#define HTTP_H
3
4#define HTTP_200 "HTTP/1.1 200 OK\r\n"
5#define HTTP_204 "HTTP/1.1 204 No Content\r\n"
6#define HTTP_206 "HTTP/1.1 206 Partial Content\r\n"
7#define HTTP_400 "HTTP/1.1 400 Bad Request\r\n"
8#define HTTP_403 "HTTP/1.1 403 Forbidden\r\n"
9#define HTTP_404 "HTTP/1.1 404 Not Found\r\n"
10#define HTTP_405 "HTTP/1.1 405 Method Not Allowed\r\n"
11#define HTTP_416 "HTTP/1.1 416 Range Not Satisfiable\r\n"
12#define HTTP_500 "HTTP/1.1 500 Internal Server Error\r\n"
13
14#define HTTP_BIN "Content-Type: application/octet-stream\r\n"
15#define HTTP_CLOSE "Connection: close\r\n"
16#define HTTP_CRG "Content-Range: bytes %zu-%zu/%zu\r\n"
17#define HTTP_CTYPE "Content-Type: %s\r\n"
18#define HTTP_JSON "Content-Type: application/json\r\n"
19#define HTTP_LENGTH "Content-Length: %zu\r\n"
20#define HTTP_RANGE "Accept-Ranges: bytes\r\n"
21#define HTTP_TEXT "Content-Type: text/plain\r\n"
22
23enum {
24 RANGE_NONE = 0, /* no range header */
25 RANGE_OK = 1, /* valid satisfiable range */
26 RANGE_BAD = -1, /* malformed (=> 400) */
27 RANGE_UNSAT = -2, /* unsatisfiable (=> 416) */
28};
29
30enum {
31 HTTP_REQ_MAX = 8192,
32 HTTP_RESP_MAX = 8192,
33 LISTEN_BACKLOG = 64,
34};
35
36/**
37 * @brief Handle a single HTTP request connected socket
38 *
39 * @note This does not close the socket
40 *
41 * @param c Connected client socket file descriptor
42 *
43 * @return 0=Handled (includes sending error responses), -1=Internal Server Error
44 */
45int http_handle(int c);
46
47#endif /* HTTP_H */
48