libonion
|
Typedefs | |
typedef enum onion_response_codes_e | onion_response_codes |
typedef enum onion_response_flags_e | onion_response_flags |
Enumerations | |
enum | onion_response_codes_e { HTTP_SWITCH_PROTOCOL = 101, HTTP_OK = 200, HTTP_CREATED = 201, HTTP_PARTIAL_CONTENT = 206, HTTP_MULTI_STATUS = 207, HTTP_MOVED = 301, HTTP_REDIRECT = 302, HTTP_SEE_OTHER = 303, HTTP_NOT_MODIFIED = 304, HTTP_TEMPORARY_REDIRECT = 307, HTTP_BAD_REQUEST = 400, HTTP_UNAUTHORIZED = 401, HTTP_FORBIDDEN = 403, HTTP_NOT_FOUND = 404, HTTP_METHOD_NOT_ALLOWED = 405, HTTP_INTERNAL_ERROR = 500, HTTP_NOT_IMPLEMENTED = 501, HTTP_BAD_GATEWAY = 502, HTTP_SERVICE_UNAVAILABLE = 503 } |
This is a list of standard response codes. More... | |
enum | onion_response_flags_e { OR_KEEP_ALIVE = 4, OR_LENGTH_SET = 2, OR_CLOSE_CONNECTION = 1, OR_SKIP_CONTENT = 8, OR_CHUNKED = 32, OR_CONNECTION_UPGRADE = 64, OR_HEADER_SENT = 0x0200 } |
Possible flags. More... | |
enum | onion_response_cookie_flags_e { OC_HTTP_ONLY = 1, OC_SECURE = 2 } |
Functions | |
const char * | onion_response_code_description (int code) |
onion_response * | onion_response_new (onion_request *req) |
Generates a new response object. | |
int | onion_response_free (onion_response *res) |
Frees the memory consumed by this object. Returns keep_alive status. | |
void | onion_response_set_header (onion_response *res, const char *key, const char *value) |
Adds a header to the response object. | |
void | onion_response_set_length (onion_response *res, size_t length) |
Sets the header length. Normally it should be through set_header, but as its very common and needs some procesing here is a shortcut. | |
void | onion_response_set_code (onion_response *res, int code) |
Sets the return code. | |
onion_dict * | onion_response_get_headers (onion_response *res) |
Gets the headers dictionary. | |
void | onion_response_add_cookie (onion_response *req, const char *cookiename, const char *cookievalue, time_t validity_t, const char *path, const char *domain, int flags) |
Sets a new cookie. | |
Write functions | |
Writes all the header to the given fd | |
int | onion_response_write_headers (onion_response *res) |
ssize_t | onion_response_write (onion_response *res, const char *data, size_t length) |
Writes some data to the response. | |
ssize_t | onion_response_write0 (onion_response *res, const char *data) |
Writes some data to the response. \0 ended string. | |
ssize_t | onion_response_write_html_safe (onion_response *res, const char *data) |
Writes some data to the response. \0 ended string, and encodes it if necesary into html entities to make it safe. | |
ssize_t | onion_response_printf (onion_response *res, const char *fmt,...) __attribute__((format(printf |
Writes some data to the response. Using sprintf format strings. | |
ssize_t ssize_t | onion_response_vprintf (onion_response *res, const char *fmt, va_list args) __attribute__((format(printf |
Writes some data to the response. Using sprintf format strings. va_list version. | |
ssize_t ssize_t int | onion_response_flush (onion_response *res) |
Flushes remaining data on the buffer to the listen point. |
typedef enum onion_response_codes_e onion_response_codes |
typedef enum onion_response_flags_e onion_response_flags |
This is a list of standard response codes.
Not all resposne codes are listed, as some of them may not have sense here. Check other sources for complete listings.
Possible flags.
These flags are used internally by the resposnes, but they can be the responses themselves of the handler when appropiate.
OR_KEEP_ALIVE |
Return when want to keep alive. Please also set the proper headers, specifically set the length. Otherwise it will block server side until client closes connection. |
OR_LENGTH_SET |
Response has set the length, so we may keep alive. |
OR_CLOSE_CONNECTION |
The connection will be closed when processing finishes. |
OR_SKIP_CONTENT |
This is set when the method is HEAD.
|
OR_CHUNKED |
The data is to be sent using chunk encoding. Its on if no lenght is set. |
OR_CONNECTION_UPGRADE |
The connection is upgraded (websockets). |
OR_HEADER_SENT |
The header has already been written. Its done automatically on first user write. Same id as OR_HEADER_SENT from onion_response_flags. |
const char* onion_response_code_description | ( | int | code | ) |
int onion_response_free | ( | onion_response * | res | ) |
Frees the memory consumed by this object. Returns keep_alive status.
onion_response* onion_response_new | ( | onion_request * | req | ) |
Generates a new response object.
ssize_t onion_response_printf | ( | onion_response * | res, |
const char * | fmt, | ||
... | |||
) |
Writes some data to the response. Using sprintf format strings.
void onion_response_set_code | ( | onion_response * | res, |
int | code | ||
) |
Sets the return code.
void onion_response_set_header | ( | onion_response * | res, |
const char * | key, | ||
const char * | value | ||
) |
Adds a header to the response object.
void onion_response_set_length | ( | onion_response * | res, |
size_t | length | ||
) |
Sets the header length. Normally it should be through set_header, but as its very common and needs some procesing here is a shortcut.
ssize_t ssize_t onion_response_vprintf | ( | onion_response * | res, |
const char * | fmt, | ||
va_list | args | ||
) |
Writes some data to the response. Using sprintf format strings. va_list version.
ssize_t onion_response_write | ( | onion_response * | res, |
const char * | data, | ||
size_t | length | ||
) |
Writes some data to the response.
int onion_response_write_headers | ( | onion_response * | res | ) |