1#ifndef VWS_HTTP_REQUEST_DECLARE
2#define VWS_HTTP_REQUEST_DECLARE
3
4#include "vws.h"
5#include "llhttp/llhttp.h"
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/**
12 * @struct vws_http_msg
13 * @brief Structure representing an HTTP request
14 */
15typedef struct vws_http_msg
16{
17 /**< The parser */
18 llhttp_t* parser;
19
20 /**< The parser settings */
21 llhttp_settings_t* settings;
22
23 /**< A map storing header fields. */
24 struct sc_map_str headers;
25
26 /**< The url */
27 vws_buffer* url;
28
29 /**< The body */
30 vws_buffer* body;
31
32 /**< Placeholder for header field */
33 vws_buffer* field;
34
35 /**< Placeholder for header value */
36 vws_buffer* value;
37
38 /** Flag indicates headers have been parsed. */
39 bool headers_complete;
40
41 /** Flag indicates a complete message has been parsed. */
42 bool done;
43
44} vws_http_msg;
45
46/**
47 * @brief Creates a new instance of vws_http_msg.
48 * @param mode Must be one of HTTP_REQUEST or HTTP_RESPONSE depending on the
49 * message to parse.
50 * @return The newly created vws_http_msg instance.
51 */
52vws_http_msg* vws_http_msg_new(int mode);
53
54/**
55 * @brief Parses the provided data as an HTTP request.
56 * @param req The vws_http_msg instance.
57 * @param data The data to parse.
58 * @param size The size of the data.
59 * @return The number of bytes parsed, or a negative value on error.
60 */
61int vws_http_msg_parse(vws_http_msg* req, cstr data, size_t size);
62
63/**
64 * @brief Frees the resources associated with the vws_http_msg instance.
65 * @param req The vws_http_msg instance to free.
66 */
67void vws_http_msg_free(vws_http_msg* req);
68
69#ifdef __cplusplus
70}
71#endif
72
73#endif /* VWS_HTTP_MSG_DECLARE */
74