refactor: move some stuff, add some docs

This commit is contained in:
Jef Roosens 2023-05-29 12:03:40 +02:00
parent 2fb3e2bb00
commit 9b66223a57
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
2 changed files with 47 additions and 23 deletions

View file

@ -49,6 +49,10 @@ typedef struct http_loop_ctx {
*/
http_loop_ctx *http_loop_ctx_init(http_loop_gctx *g);
/*
* Resets an already allocated context so that it can be reused for a new
* request.
*/
void http_loop_ctx_reset(http_loop_ctx *ctx);
/*
@ -56,25 +60,40 @@ void http_loop_ctx_reset(http_loop_ctx *ctx);
*/
void http_loop_ctx_free(http_loop_ctx *ctx);
/**
* Process incoming data as an HTTP request
/*
* Process incoming data as an HTTP request. This is the "handle_data" function
* for the event loop.
*/
bool http_loop_handle_request(event_loop_conn *conn);
/*
* Write the HTTP response to the file descriptor. This is the "write_data"
* function for the event loop.
*/
void http_loop_write_response(event_loop_conn *conn);
/*
* Try to parse the incoming data as an HTTP request.
*/
http_parse_error http_loop_parse_request(event_loop_conn *conn);
/*
* Try to match the parsed request with one of the defined routes, aka route the
* request.
*/
void http_loop_route_request(event_loop_conn *conn);
/*
* Advance the processing of the routed request's processing by cycling through
* the request's various steps.
*/
void http_loop_process_request(event_loop_conn *conn);
void http_loop_res_set_body(const char *body, size_t body_len);
void http_loop_res_set_type(http_response_type type);
void http_loop_write_standard_response(event_loop_conn *conn,
http_response_type type);
/*
* Set the request body to the given buffer. If owned is set to true, the body
* buffer will be free'd after the request has finished.
*/
void http_loop_res_set_body(const char *body, size_t body_len, bool owned);
/**
* Initialize a new http loop