libexpress 0.0.1
Express Server Framework in C
Loading...
Searching...
No Matches
res.h
Go to the documentation of this file.
1
8#ifndef __LIBEXPRESS_RES_H
9#define __LIBEXPRESS_RES_H 1
10
11/* Personal libraries */
12#include <libhmap/hmap.h>
13
14/* libc */
15#include <stdbool.h>
16
20#ifndef __BASE__
21#define __BASE__ ""
22#endif
23
27typedef struct {
28 u_int16_t status;
29 hmap_t *headers;
30 const char *body;
31 bool sent; // To check if response has already been sent
32 int client; // To identify who to send the response to
33} res_t;
34
41void status_codes_init(void);
42
49void mime_init(void);
50
60void res_send(res_t *res);
61
76void res_send_file(res_t *res, const char *path);
77
78/* Utility */
79
86void set_res_body(res_t* res, char* body);
87
94void set_res_status(res_t* res, u_int16_t status);
95
107void set_res_header(res_t* res, const char* header, char* value);
108
116char* get_res_header(res_t* res, const char* header);
117
118#endif
void set_res_header(res_t *res, const char *header, char *value)
Set a particular header of the response.
Definition: res.c:262
char * get_res_header(res_t *res, const char *header)
Get the value of a particular header of the response.
Definition: res.c:268
void status_codes_init(void)
Initialize the status_codes hmap.
Definition: res.c:14
void set_res_status(res_t *res, u_int16_t status)
Set the status code of the response.
Definition: res.c:243
void res_send(res_t *res)
Send response to client.
Definition: res.c:129
void res_send_file(res_t *res, const char *path)
Send a file to the client.
Definition: res.c:180
void set_res_body(res_t *res, char *body)
Set the body of the response.
Definition: res.c:233
void mime_init(void)
Initialize the mime_types hmap.
Definition: res.c:70
Response being sent to the client.
Definition: res.h:27