summaryrefslogtreecommitdiff
path: root/include/http.h
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-07-08 15:06:33 -0300
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-07-08 15:06:33 -0300
commit7a388dad85152a203033c14fee3c64607301865a (patch)
tree054b7bb03883576a8b68da8470908ff259e029d4 /include/http.h
libactivity: (tmp name) http request parse
the parse works via callbacks, registered to a method and path. further work will be done to simplify extraction of path, and to make the request struct more private. missing the parsing and handling of reponses. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'include/http.h')
-rw-r--r--include/http.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/http.h b/include/http.h
new file mode 100644
index 0000000..c550b15
--- /dev/null
+++ b/include/http.h
@@ -0,0 +1,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