feat(lnm): more request processing code
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Jef Roosens 2023-11-30 21:04:13 +01:00
parent 8c21ccf58b
commit 77b62825a6
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 120 additions and 19 deletions

View file

@ -5,6 +5,7 @@
#include "lnm/common.h"
#include "lnm/http/req.h"
#include "lnm/http/res.h"
typedef struct lnm_loop lnm_http_loop;
@ -14,14 +15,14 @@ typedef struct lnm_http_step lnm_http_step;
typedef struct lnm_http_route lnm_http_route;
typedef enum lnm_step_err {
lnm_step_err_done = 0,
lnm_step_err_io_needed,
lnm_step_err_close,
lnm_step_err_res,
} lnm_step_err;
typedef enum lnm_http_step_err {
lnm_http_step_err_done = 0,
lnm_http_step_err_io_needed,
lnm_http_step_err_close,
lnm_http_step_err_res,
} lnm_http_step_err;
typedef lnm_step_err (*lnm_http_step_fn)(lnm_http_conn *conn);
typedef lnm_http_step_err (*lnm_http_step_fn)(lnm_http_conn *conn);
typedef lnm_err (*lnm_http_ctx_init_fn)(void **c_ctx, void *gctx);
@ -84,9 +85,22 @@ void lnm_http_loop_route_add(lnm_http_loop *hl, lnm_http_route *route);
* Represents what state an HTTP loop request is currently in.
*/
typedef enum lnm_http_loop_state {
// Parse the HTTP request
lnm_http_loop_state_parse_req = 0,
// Route the request
lnm_http_loop_state_route,
// Parse specific headers (e.g. Content-Length)
lnm_http_loop_state_parse_headers,
// Execute the various steps defined for the route
lnm_http_loop_state_steps,
// Write the response status line
lnm_http_loop_state_write_status_line,
// Write the various response headers
lnm_http_loop_state_write_headers,
// Write the request body
lnm_http_loop_state_write_body,
// Clean up the request and reset the state for a next request
lnm_http_loop_state_finish,
} lnm_http_loop_state;
typedef struct lnm_http_loop_gctx {
@ -103,7 +117,9 @@ typedef struct lnm_http_loop_gctx {
typedef struct lnm_http_loop_ctx {
lnm_http_loop_state state;
lnm_http_req req;
lnm_http_res res;
lnm_http_route *route;
lnm_http_step *cur_step;
lnm_http_loop_gctx *g;
void *c;
} lnm_http_loop_ctx;

View file

@ -0,0 +1,30 @@
#ifndef LNM_HTTP_RES
#define LNM_HTTP_RES
#include <stdbool.h>
#include "lnm/http/consts.h"
typedef struct lnm_http_res_header {
struct {
char *s;
size_t len;
bool owned;
} name;
struct {
char *s;
size_t len;
bool owned;
} value;
struct lnm_http_res_header *next;
} lnm_http_res_header;
typedef struct lnm_http_res {
lnm_http_status status;
struct {
lnm_http_res_header *head;
lnm_http_res_header *current;
} headers;
} lnm_http_res;
#endif