-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.h
60 lines (53 loc) · 1.55 KB
/
http.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef __HTTP_H
#define __HTTP_H
#include <src/headers.h>
#include <src/status_codes.h>
#include <sys/time.h>
enum http_method {
M_GET,
M_HEAD,
M_POST,
M_PUT,
M_DELETE,
M_CONNECT,
M_OPTIONS,
M_TRACE,
M_UNKNOWN,
};
typedef struct {
http_status_code status_code;
char *message; /* HTTP response content */
size_t message_len;
struct http_header *headers_arr; /* linked list of headers */
size_t num_headers;
int http_minor_ver;
/* bit mask of flags */
int res_flags;
} http_res;
typedef struct {
/* an independent buffer holding the request path */
char *path;
size_t path_len, path_bufcap;
enum http_method method;
int minor_ver;
/* hashset of headers of HTTP req, each headers value is copied into a
* buffer inside this struct and is indepedent of the recv buffer */
struct header_hashset *headers;
size_t num_headers;
/* points to content of HTTP req (points inside recv_buffer) from client */
char *message;
size_t message_length;
} http_req;
typedef struct {
char *ROOT_PATH;
char *PORT;
char *SERVNAME;
struct timeval timeout;
/* generates a reponse to request.
* - must use malloc() to allocate http_res.headers_arr, http_res.message
* - must set all fields of http_res
*/
http_res (*handler)(http_req *request);
} config;
int init_server(config conf);
#endif /* __HTTP_H */