feat: response bodies from char buffers; generated responses
This commit is contained in:
parent
62348c14f5
commit
2fb3e2bb00
12 changed files with 163 additions and 108 deletions
|
|
@ -53,6 +53,8 @@ typedef struct event_loop {
|
|||
void (*ctx_free)(void *ctx);
|
||||
// Function that processes incoming data
|
||||
bool (*handle_data)(event_loop_conn *conn);
|
||||
// Function that writes outgoing data
|
||||
void (*write_data)(event_loop_conn *conn);
|
||||
} event_loop;
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -1,20 +1,13 @@
|
|||
#ifndef HTTP
|
||||
#define HTTP
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "picohttpparser.h"
|
||||
|
||||
#define HTTP_MAX_ALLOWED_HEADERS 8
|
||||
#define HTTP_MAX_ALLOWED_HEADERS 16
|
||||
|
||||
extern const char http_404[];
|
||||
extern const size_t http_404_len;
|
||||
extern const char http_405[];
|
||||
extern const size_t http_405_len;
|
||||
extern const char http_500[];
|
||||
extern const size_t http_500_len;
|
||||
extern const char http_501[];
|
||||
extern const size_t http_501_len;
|
||||
extern const char *http_response_type_names[5][32];
|
||||
|
||||
typedef enum http_request_method {
|
||||
|
|
@ -120,9 +113,14 @@ typedef enum http_response_type {
|
|||
|
||||
typedef struct http_response {
|
||||
http_response_type type;
|
||||
const char *head;
|
||||
size_t head_len;
|
||||
size_t head_written;
|
||||
const char *body;
|
||||
size_t body_len;
|
||||
size_t body_written;
|
||||
// If false, the body won't be freed
|
||||
bool owns_body;
|
||||
} http_response;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ http_loop_gctx *http_loop_gctx_init();
|
|||
typedef struct http_loop_ctx {
|
||||
http_request req;
|
||||
http_response res;
|
||||
bool flush;
|
||||
http_route *route;
|
||||
size_t current_step;
|
||||
http_loop_gctx *g;
|
||||
|
|
@ -62,12 +61,18 @@ void http_loop_ctx_free(http_loop_ctx *ctx);
|
|||
*/
|
||||
bool http_loop_handle_request(event_loop_conn *conn);
|
||||
|
||||
void http_loop_write_response(event_loop_conn *conn);
|
||||
|
||||
http_parse_error http_loop_parse_request(event_loop_conn *conn);
|
||||
|
||||
bool http_loop_route_request(event_loop_conn *conn);
|
||||
void http_loop_route_request(event_loop_conn *conn);
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue