HTTP response. More...
Typedefs | |
| typedef struct vtm_http_res | vtm_http_res |
Enumerations | |
| enum | vtm_http_res_mode { VTM_HTTP_RES_MODE_FIXED, VTM_HTTP_RES_MODE_CHUNKED } |
| enum | vtm_http_res_act { VTM_HTTP_RES_ACT_CLOSE_CON, VTM_HTTP_RES_ACT_KEEP_CON, VTM_HTTP_RES_ACT_UPGRADE_WS } |
Functions | |
| VTM_API int | vtm_http_res_begin (vtm_http_res *res, enum vtm_http_res_mode mode, int status) |
| VTM_API int | vtm_http_res_header (vtm_http_res *res, const char *name, const char *value) |
| VTM_API int | vtm_http_res_body_str (vtm_http_res *res, const char *data) |
| VTM_API int | vtm_http_res_body_raw (vtm_http_res *res, const char *src, size_t len) |
| VTM_API int | vtm_http_res_body_emt (vtm_http_res *res, struct vtm_socket_emitter *se) |
| VTM_API int | vtm_http_res_set_action (vtm_http_res *res, enum vtm_http_res_act act, void *data) |
| VTM_API int | vtm_http_res_end (vtm_http_res *res) |
| VTM_API int | vtm_http_res_set_date (vtm_http_res *res) |
| VTM_API bool | vtm_http_res_was_started (vtm_http_res *res) |
| VTM_API bool | vtm_http_res_was_sent (vtm_http_res *res) |
| VTM_API enum vtm_http_version | vtm_http_res_get_version (vtm_http_res *res) |
| enum vtm_http_res_mode |
| enum vtm_http_res_act |
| VTM_API int vtm_http_res_begin | ( | vtm_http_res * | res, |
| enum vtm_http_res_mode | mode, | ||
| int | status | ||
| ) |
Initializes and starts the response with mode and status code.
This must always be the first call on a response handle.
| res | the response |
| mode | the mode how the body is sent |
| status | one of the three digit HTTP status codes |
| VTM_API int vtm_http_res_header | ( | vtm_http_res * | res, |
| const char * | name, | ||
| const char * | value | ||
| ) |
Sets a response header.
| res | the response |
| name | the name of the header field |
| value | the value for the header field |
| VTM_API int vtm_http_res_body_str | ( | vtm_http_res * | res, |
| const char * | data | ||
| ) |
Adds a string to the response body.
| res | the response |
| data | the string that should be appended to the body |
| VTM_API int vtm_http_res_body_raw | ( | vtm_http_res * | res, |
| const char * | src, | ||
| size_t | len | ||
| ) |
Adds a chunk of memory to the response body
| res | the response |
| src | pointer to the memory chunk |
| len | length of memory region in bytes |
| VTM_API int vtm_http_res_body_emt | ( | vtm_http_res * | res, |
| struct vtm_socket_emitter * | se | ||
| ) |
Lets the response body be defined by a socket emitter.
The emitter is automatically released.
| res | the response |
| se | pointer to the socket emitter |
| VTM_API int vtm_http_res_set_action | ( | vtm_http_res * | res, |
| enum vtm_http_res_act | act, | ||
| void * | data | ||
| ) |
Sets the action that is performed after the response has been sent.
This is used for example when upgrading an HTTP connection to a WebSocket connection.
The action can only be changed before the body was written.
| res | the response |
| act | the action that should be performed |
| data | additional data needed by the action |
| VTM_API int vtm_http_res_end | ( | vtm_http_res * | res | ) |
Marks the response as complete and starts sending.
| res | the response that is complete |
| VTM_API int vtm_http_res_set_date | ( | vtm_http_res * | res | ) |
Sets HTTP date header.
| res | the response |
| VTM_API bool vtm_http_res_was_started | ( | vtm_http_res * | res | ) |
Checks if the reponse was already started.
| res | the response that should be checked |
| VTM_API bool vtm_http_res_was_sent | ( | vtm_http_res * | res | ) |
Checks if the response was sent by vtm_http_res_end().
| res | the response that should be checked |
| VTM_API enum vtm_http_version vtm_http_res_get_version | ( | vtm_http_res * | res | ) |
Gets the HTTP version of the response
res the response whose version should be retrieved
1.8.8