Blob


1 /*
2 * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 enum http_method {
18 METHOD_UNKNOWN,
19 METHOD_GET,
20 METHOD_POST,
21 };
23 struct request {
24 char buf[BUFSIZ];
25 size_t len;
27 char *path;
28 int method;
29 char *ctype;
30 size_t clen;
31 };
33 struct reswriter {
34 int fd;
35 int err;
36 int chunked;
37 char buf[BUFSIZ];
38 size_t len;
39 };
41 int http_parse(struct request *, int);
42 int http_read(struct request *, int);
43 void http_response_init(struct reswriter *, int);
44 int http_reply(struct reswriter *, int, const char *, const char *);
45 int http_flush(struct reswriter *);
46 int http_write(struct reswriter *, const char *, size_t);
47 int http_writes(struct reswriter *, const char *);
48 int http_fmt(struct reswriter *, const char *, ...);
49 int http_urlescape(struct reswriter *, const char *);
50 int http_htmlescape(struct reswriter *, const char *);
51 int http_close(struct reswriter *);
52 void http_free_request(struct request *);