summaryrefslogtreecommitdiffhomepage
path: root/http.h
blob: 462984626149dec505e2553b27f43825947fe985 (plain)
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
#ifndef HTTP_H
#define HTTP_H

struct span
{
	int start;
	int length;
};

struct header
{
	struct span name;
	struct span value;
};

struct request
{
	int (* step)(struct request *);
	char * data;
	int length;
	int position;
	struct span method;
	struct span path;
	struct span version;
	struct header * headers;
	struct span body;
};

enum status
{
	STATUS_OK = 200,
	STATUS_BAD_REQUEST = 400,
	STATUS_METHOD_NOT_ALLOWED = 405,
	STATUS_REQUEST_TIMEOUT = 408,
	STATUS_INTERNAL_SERVER_ERROR = 500,
	STATUS_NOT_IMPLEMENTED = 501,
	STATUS_VERSION_NOT_SUPPORTED = 505,
};

extern const char * status_str[];

struct request * new_request(void);
void free_request(struct request *);

int respond_only_status(int, enum status);
int respond_with_body(int, enum status, const char *, int);

int collect_request(int, char **);

int parse_method(struct request *);
int parse_path(struct request *);
int parse_version(struct request *);

#endif // HTTP_H