summaryrefslogtreecommitdiff
path: root/include/http.h
blob: c550b15dca3be2eb6dc9d0b55fb4a9eb5494fe6e (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
#ifndef _HTTP_H_
#define _HTTP_H_
#include <stdbool.h>

#include "buffer.h"

//static const char *supported_http_versions[] = { "1.1" };

struct header_item;
#define MAX_HEADERS 512
struct header_list {
	struct header_item *items[MAX_HEADERS];
};

struct request {
	char http_version[4];
	char *method;
	char *path;
	char *query;
	char *body;
	char *data;
	struct header_list header;
};

struct reply {
	int status;
	char *body;
};

typedef struct reply *(request_callback)(struct request *, void *);

struct http;

struct http *http_init(void);
bool http_register_handler(struct http *http, char *method, char *path,
		void *data, request_callback *callback);
struct reply *http_handle_request(struct http *http, struct buffer *req);
struct buffer *http_build_reply(struct reply *reply);
const char *http_get_header(struct request *req, const char *key);

#endif