tinywebd

view src/http.h @ 5:def49a046566

serialization of responses
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 17 Apr 2015 01:57:00 +0300
parents 852a745503cf
children 5ec50ca0d071
line source
1 #ifndef HTTP_H_
2 #define HTTP_H_
4 enum http_method {
5 HTTP_UNKNOWN,
6 HTTP_OPTIONS,
7 HTTP_GET,
8 HTTP_HEAD,
9 HTTP_POST,
10 HTTP_PUT,
11 HTTP_DELETE,
12 HTTP_TRACE,
13 HTTP_CONNECT,
15 NUM_HTTP_METHODS
16 };
18 struct http_req_header {
19 enum http_method method;
20 char *uri;
21 int ver_major, ver_minor; /* http version */
22 char **hdrfields;
23 int num_hdrfields;
24 int body_offset;
25 };
27 struct http_resp_header {
28 int status;
29 int ver_major, ver_minor;
30 char **fields;
31 int num_fields;
32 };
34 #define HTTP_HDR_OK 0
35 #define HTTP_HDR_INVALID -1
36 #define HTTP_HDR_NOMEM -2
37 #define HTTP_HDR_PARTIAL -3
39 int http_parse_header(struct http_req_header *hdr, const char *buf, int bufsz);
40 void http_print_header(struct http_req_header *hdr);
41 void http_destroy_header(struct http_req_header *hdr);
43 int http_init_resp(struct http_resp_header *resp);
44 int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...);
45 void http_destroy_resp(struct http_resp_header *resp);
46 int http_serialize_resp(struct http_resp_header *resp, char *buf);
48 const char *http_strmsg(int code);
50 #endif /* HTTP_H_ */