libexpress 0.0.1
Express Server Framework in C
|
This contains all the response related material. More...
#include <libhmap/hmap.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | res_t |
Response being sent to the client. More... | |
Macros | |
#define | __BASE__ "" |
Base from where files are looked up. | |
Functions | |
void | status_codes_init (void) |
Initialize the status_codes hmap. More... | |
void | mime_init (void) |
Initialize the mime_types hmap. More... | |
void | res_send (res_t *res) |
Send response to client. More... | |
void | res_send_file (res_t *res, const char *path) |
Send a file to the client. More... | |
void | set_res_body (res_t *res, char *body) |
Set the body of the response. More... | |
void | set_res_status (res_t *res, u_int16_t status) |
Set the status code of the response. More... | |
void | set_res_header (res_t *res, const char *header, char *value) |
Set a particular header of the response. More... | |
char * | get_res_header (res_t *res, const char *header) |
Get the value of a particular header of the response. More... | |
This contains all the response related material.
char * get_res_header | ( | res_t * | res, |
const char * | header | ||
) |
Get the value of a particular header of the response.
res | Response |
header | Header name |
void mime_init | ( | void | ) |
Initialize the mime_types
hmap.
The mime_types
is initialized to contain all of the popular extensions and their mime-types.
void res_send | ( | res_t * | res | ) |
Send response to client.
This sends the response to the client (gets the client ID through res->client) and sets the res->sent to true. It prevents sending a response if res->sent is already true.
res | Response |
void res_send_file | ( | res_t * | res, |
const char * | path | ||
) |
Send a file to the client.
It sends the file at the specified path to the client. The usage can be like the following
#undef BASE #define BASE "/home/user/server"
res_send_file(res, BASE "/index.html");
res | Response |
path | Absolute path of the file. |
Malloc gives error on modifying the pointer itself
void set_res_body | ( | res_t * | res, |
char * | body | ||
) |
Set the body of the response.
res | Response |
body | Body to send to client. |
void set_res_header | ( | res_t * | res, |
const char * | header, | ||
char * | value | ||
) |
Set a particular header of the response.
It sets a header
to the given value
in the response sent by the client and any case of setting it multiple times will lead to the latest one being considered.
res | Response |
header | Header name |
value | Value |
void set_res_status | ( | res_t * | res, |
u_int16_t | status | ||
) |
Set the status code of the response.
res | Response |
status | Status Code for HTTP Response |
void status_codes_init | ( | void | ) |
Initialize the status_codes
hmap.
The status_codes
is initialized to contain all of the status codes as well as their message.