tinywebd

view libtinyweb/src/http.h @ 12:86f703031228

Attribution headers
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 19 Apr 2015 00:01:01 +0300
parents 0dd50a23f3dd
children
line source
1 /* tinyweb - tiny web server library and daemon
2 * Author: John Tsiombikas <nuclear@member.fsf.org>
3 *
4 * This program is placed in the public domain. Feel free to use it any
5 * way you like. Mentions and retaining this attribution header will be
6 * appreciated, but not required.
7 */
8 #ifndef HTTP_H_
9 #define HTTP_H_
11 enum http_method {
12 HTTP_UNKNOWN,
13 HTTP_OPTIONS,
14 HTTP_GET,
15 HTTP_HEAD,
16 HTTP_POST,
17 HTTP_PUT,
18 HTTP_DELETE,
19 HTTP_TRACE,
20 HTTP_CONNECT,
22 NUM_HTTP_METHODS
23 };
25 struct http_req_header {
26 enum http_method method;
27 char *uri;
28 int ver_major, ver_minor; /* http version */
29 char **hdrfields;
30 int num_hdrfields;
31 int body_offset;
32 };
34 struct http_resp_header {
35 int status;
36 int ver_major, ver_minor;
37 char **fields;
38 int num_fields;
39 };
41 #define HTTP_HDR_OK 0
42 #define HTTP_HDR_INVALID -1
43 #define HTTP_HDR_NOMEM -2
44 #define HTTP_HDR_PARTIAL -3
46 int http_parse_request(struct http_req_header *hdr, const char *buf, int bufsz);
47 void http_log_request(struct http_req_header *hdr);
48 void http_destroy_request(struct http_req_header *hdr);
50 int http_init_resp(struct http_resp_header *resp);
51 int http_add_resp_field(struct http_resp_header *resp, const char *fmt, ...);
52 void http_destroy_resp(struct http_resp_header *resp);
53 int http_serialize_resp(struct http_resp_header *resp, char *buf);
55 const char *http_strmsg(int code);
57 #endif /* HTTP_H_ */