feat: support adding up to 4 headers
This commit is contained in:
parent
8f9de37a95
commit
dd0ba31506
6 changed files with 69 additions and 6 deletions
|
|
@ -9,6 +9,7 @@
|
|||
#define HTTP_MAX_ALLOWED_HEADERS 16
|
||||
|
||||
extern const char *http_response_type_names[5][32];
|
||||
extern const char *http_header_names[];
|
||||
|
||||
typedef enum http_request_method {
|
||||
http_get = 0,
|
||||
|
|
@ -111,6 +112,17 @@ typedef enum http_response_type {
|
|||
http_network_authentication_required = 511
|
||||
} http_response_type;
|
||||
|
||||
typedef enum http_header {
|
||||
http_header_connection = 0,
|
||||
http_header_redirect = 1
|
||||
} http_header;
|
||||
|
||||
typedef struct http_response_header {
|
||||
http_header type;
|
||||
const char *value;
|
||||
bool owned;
|
||||
} http_response_header;
|
||||
|
||||
typedef struct http_response {
|
||||
http_response_type type;
|
||||
const char *head;
|
||||
|
|
@ -121,6 +133,8 @@ typedef struct http_response {
|
|||
size_t body_written;
|
||||
// If false, the body won't be freed
|
||||
bool owns_body;
|
||||
http_response_header headers[4];
|
||||
size_t header_count;
|
||||
} http_response;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -97,6 +97,9 @@ void http_loop_process_request(event_loop_conn *conn);
|
|||
void http_loop_res_set_body(http_loop_ctx *ctx, const char *body,
|
||||
size_t body_len, bool owned);
|
||||
|
||||
void http_loop_res_add_header(http_loop_ctx *ctx, http_header type,
|
||||
const char *value, bool owned);
|
||||
|
||||
/**
|
||||
* Initialize a new http loop
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue