From 7a388dad85152a203033c14fee3c64607301865a Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sat, 8 Jul 2023 15:06:33 -0300 Subject: 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 --- include/http.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/http.h (limited to 'include/http.h') 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 + +#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 -- cgit v1.2.3