feat: support serving files
This commit is contained in:
parent
34ecb7eb40
commit
095f86ad72
5 changed files with 54 additions and 16 deletions
|
|
@ -126,12 +126,18 @@ typedef struct http_response_header {
|
|||
bool owned;
|
||||
} http_response_header;
|
||||
|
||||
typedef enum http_response_body_type {
|
||||
http_response_body_buf = 0,
|
||||
http_response_body_file = 1
|
||||
} http_response_body_type;
|
||||
|
||||
typedef struct http_response {
|
||||
http_response_type type;
|
||||
const char *head;
|
||||
size_t head_len;
|
||||
size_t head_written;
|
||||
const char *body;
|
||||
http_response_body_type body_type;
|
||||
void *body;
|
||||
size_t body_len;
|
||||
size_t body_written;
|
||||
// If false, the body won't be freed
|
||||
|
|
|
|||
|
|
@ -94,8 +94,10 @@ void http_loop_process_request(event_loop_conn *conn);
|
|||
* 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(http_loop_ctx *ctx, const char *body,
|
||||
size_t body_len, bool owned);
|
||||
void http_loop_res_set_body_buf(http_loop_ctx *ctx, const char *body,
|
||||
size_t body_len, bool owned);
|
||||
|
||||
void http_loop_res_set_body_file(http_loop_ctx *ctx, const char *filename);
|
||||
|
||||
void http_loop_res_add_header(http_loop_ctx *ctx, http_header type,
|
||||
const char *value, bool owned);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue