libonion
|
Data Structures | |
struct | onion_response_t |
The response. More... |
Functions | |
int | onion_response_flush (onion_response *res) |
Writes all buffered output waiting for sending.If header has not been sent yet (delayed), it uses a temporary buffer to send it now. This way header can use the buffer_size information to send the proper content-length, even when it wasnt properly set by programmer. Whith this information its possib to keep alive the connection on more cases. | |
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 the given string to the res, but encodes the data using html entitiesThe encoding mens that <html> whould become <html> | |
onion_dict * | onion_response_get_headers (onion_response *res) |
Returns the headers dictionary, so user can add repeated headersOnly simple use case is to add several coockies; using normal set_header is not possible, but accessing the dictionary user can add repeated headers without problem. | |
void | onion_response_add_cookie (onion_response *res, const char *cookiename, const char *cookievalue, time_t validity_t, const char *path, const char *domain, int flags) |
Sets a new cookie into the response. | |
onion_response * | onion_response_t::onion_response_new (onion_request *req) |
Generates a new response object. | |
onion_connection_status | onion_response_t::onion_response_free (onion_response *res) |
Frees the memory consumed by this object. | |
void | onion_response_t::onion_response_set_header (onion_response *res, const char *key, const char *value) |
Adds a header to the response object. | |
void | onion_response_t::onion_response_set_length (onion_response *res, size_t len) |
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_t::onion_response_set_code (onion_response *res, int code) |
Sets the return code. | |
static void | onion_response_t::write_header (onion_response *res, const char *key, const char *value, int flags) |
Helper that is called on each header, and writes the header. | |
int | onion_response_t::onion_response_write_headers (onion_response *res) |
Writes all the header to the given response. | |
ssize_t | onion_response_t::onion_response_write (onion_response *res, const char *data, size_t length) |
Write some response data. | |
ssize_t | onion_response_t::onion_response_printf (onion_response *res, const char *fmt,...) |
Writes some data to the response. Using sprintf format strings. | |
ssize_t | onion_response_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 args version. | |
const char * | onion_response_t::onion_response_code_description (int code) |
Returns a const char * string with the code description. |
void onion_response_add_cookie | ( | onion_response * | res, |
const char * | cookiename, | ||
const char * | cookievalue, | ||
time_t | validity_t, | ||
const char * | path, | ||
const char * | domain, | ||
int | flags | ||
) |
Sets a new cookie into the response.
Sets a new cookie.
res | Response object |
cookiename | Name for the cookie |
cookievalue | Value for the cookis |
validity_t | Seconds this cookie is valid (added to current datetime). -1 to do not expire, 0 to expire inmediatly. |
path | Cookie valid only for this path |
Domain | Cookie valid only for this domain (www.example.com, or *.example.com). |
flags | Flags from onion_cookie_flags_t, for example OC_SECURE or OC_HTTP_ONLY |
If validity is 0, cookie is set to expire right now.
References OC_HTTP_ONLY, OC_SECURE, ONION_DEBUG, and onion_response_t::onion_response_set_header().
const char * onion_response_code_description | ( | int | code | ) |
Returns a const char * string with the code description.
References HTTP_BAD_GATEWAY, HTTP_BAD_REQUEST, HTTP_CREATED, HTTP_FORBIDDEN, HTTP_INTERNAL_ERROR, HTTP_METHOD_NOT_ALLOWED, HTTP_MOVED, HTTP_MULTI_STATUS, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_REDIRECT, HTTP_SEE_OTHER, HTTP_SERVICE_UNAVAILABLE, HTTP_SWITCH_PROTOCOL, HTTP_TEMPORARY_REDIRECT, and HTTP_UNAUTHORIZED.
Referenced by onion_response_t::onion_response_write_headers().
int onion_response_flush | ( | onion_response * | res | ) |
Writes all buffered output waiting for sending.If header has not been sent yet (delayed), it uses a temporary buffer to send it now. This way header can use the buffer_size information to send the proper content-length, even when it wasnt properly set by programmer. Whith this information its possib to keep alive the connection on more cases.
Flushes remaining data on the buffer to the listen point.
References onion_response_t::buffer, onion_response_t::buffer_pos, onion_request_t::connection, onion_response_t::flags, onion_request_t::listen_point, OCS_CLOSE_CONNECTION, ONION_DEBUG0, ONION_ERROR, onion_response_t::onion_response_write(), onion_response_t::onion_response_write_headers(), ONION_WARNING, OR_CHUNKED, OR_HEADER_SENT, OR_SKIP_CONTENT, onion_response_t::request, onion_response_t::sent_bytes, onion_response_t::sent_bytes_total, and onion_listen_point_t::write.
Referenced by onion_empty_output_buffer(), onion_handler_t::onion_handler_handle(), onion_response_t::onion_response_free(), onion_response_t::onion_response_write(), onion_response_t::onion_response_write_headers(), onion_term_destination(), and onion_webdav_propfind().
onion_connection_status onion_response_free | ( | onion_response * | res | ) |
Frees the memory consumed by this object.
This function returns the close status: OR_KEEP_ALIVE or OR_CLOSE_CONNECTION as needed.
References onion_response_t::buffer, onion_response_t::buffer_pos, onion_response_t::code, onion_request_t::connection, onion_request_t::flags, onion_response_t::flags, onion_request_t::fullpath, onion_response_t::headers, onion_response_t::length, onion_request_t::listen_point, OCS_CLOSE_CONNECTION, OCS_KEEP_ALIVE, OF_NOINFO, ONION_DEBUG0, onion_dict_t::onion_dict_free(), ONION_INFO, onion_log_flags, onion_low_free(), onion_request_t::onion_request_get_client_description(), onion_request_t::onion_request_keep_alive(), onion_request_t::onion_request_methods, onion_response_flush(), onion_response_t::onion_response_set_length(), onion_response_t::onion_response_write_headers(), OR_CHUNKED, OR_HEADER_SENT, OR_METHODS, OR_SKIP_CONTENT, onion_response_t::request, onion_response_t::sent_bytes, and onion_listen_point_t::write.
Referenced by onion_request_process().
onion_dict* onion_response_get_headers | ( | onion_response * | res | ) |
Returns the headers dictionary, so user can add repeated headersOnly simple use case is to add several coockies; using normal set_header is not possible, but accessing the dictionary user can add repeated headers without problem.
Gets the headers dictionary.
References onion_response_t::headers.
onion_response * onion_response_new | ( | onion_request * | req | ) |
Generates a new response object.
This response is generated from a request, and gets from there the writer and writer data.
Also fills some important data, as server Id, License type, and the default content type.
Default content type is HTML, as normally this is what is needed. This is nontheless just the default, and can be changed to any other with a call to:
onion_response_set_header(res, "Content-Type", my_type);
The response object must be freed with onion_response_free, which also returns the keep alive status.
onion_response objects are passed by onion internally to process the request, and should not be created by user normally. Nontheless the option exist.
References onion_response_t::buffer_pos, onion_response_t::code, onion_response_t::flags, onion_response_t::headers, onion_response_t::length, OD_DUP_VALUE, ONION_DEBUG, onion_dict_t::onion_dict_add(), onion_dict_t::onion_dict_new(), onion_low_free(), onion_low_malloc(), onion_low_strdup(), onion_response_t::request, onion_response_t::sent_bytes, and onion_response_t::sent_bytes_total.
Referenced by onion_request_process().
ssize_t onion_response_printf | ( | onion_response * | res, |
const char * | fmt, | ||
... | |||
) |
Writes some data to the response. Using sprintf format strings.
References onion_response_t::onion_response_vprintf().
Referenced by onion_error_exit(), onion_handler_export_local_directory(), onion_handler_export_local_header_default(), and onion_response_t::onion_response_write_headers().
void onion_response_set_code | ( | onion_response * | res, |
int | code | ||
) |
Sets the return code.
References onion_response_t::code.
Referenced by onion_error_exit(), onion_handler_auth_pam_handler(), onion_handler_static_handler(), onion_shortcut_response_extra_headers(), onion_shortcut_response_file(), onion_webdav_handler(), onion_webdav_propfind(), and onion_websocket_t::onion_websocket_new().
void onion_response_set_header | ( | onion_response * | res, |
const char * | key, | ||
const char * | value | ||
) |
Adds a header to the response object.
References onion_response_t::headers, OD_DUP_ALL, OD_REPLACE, ONION_DEBUG0, and onion_dict_t::onion_dict_add().
Referenced by onion_handler_auth_pam_handler(), onion_handler_export_local_directory(), onion_jpeg_response(), onion_png_response(), onion_response_add_cookie(), onion_response_t::onion_response_set_length(), onion_shortcut_response_extra_headers(), onion_shortcut_response_file(), onion_shortcut_response_json(), onion_webdav_handler(), onion_webdav_options(), onion_webdav_propfind(), and onion_websocket_t::onion_websocket_new().
void onion_response_set_length | ( | onion_response * | res, |
size_t | len | ||
) |
Sets the header length. Normally it should be through set_header, but as its very common and needs some procesing here is a shortcut.
References onion_response_t::flags, onion_response_t::length, onion_response_t::onion_response_set_header(), ONION_WARNING, OR_HEADER_SENT, OR_LENGTH_SET, and onion_response_t::sent_bytes.
Referenced by onion_handler_auth_pam_handler(), onion_handler_t::onion_handler_handle(), onion_handler_opack_handler(), onion_handler_static_handler(), onion_response_t::onion_response_free(), onion_shortcut_response_extra_headers(), onion_shortcut_response_file(), onion_webdav_options(), and onion_webdav_propfind().
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 args version.
args | va_list of arguments |
References ONION_ERROR, onion_low_free(), onion_low_scalar_malloc(), and onion_response_t::onion_response_write().
Referenced by onion_response_t::onion_response_printf().
ssize_t onion_response_write | ( | onion_response * | res, |
const char * | data, | ||
size_t | length | ||
) |
Write some response data.
This is the main write data function. If the headers have not been sent yet, they are now.
It's internally used also by the write0 and printf versions.
Also it does some buffering, so data is not sent as written by code, but only in chunks. These chunks are when the response is finished, or when the internal buffer is full. This helps performance, and eases the programming on the user side.
If length is 0, forces the write of pending data.
References onion_response_t::buffer, onion_response_t::buffer_pos, onion_response_t::flags, OCS_CLOSE_CONNECTION, ONION_DEBUG, onion_response_flush(), onion_response_t::onion_response_write_headers(), OR_HEADER_SENT, and OR_SKIP_CONTENT.
Referenced by onion_handler_auth_pam_handler(), onion_handler_static_handler(), onion_response_flush(), onion_response_t::onion_response_vprintf(), onion_response_write0(), onion_response_t::onion_response_write_headers(), onion_shortcut_response_extra_headers(), onion_shortcut_response_file(), onion_webdav_propfind(), onion_websocket_t::onion_websocket_new(), and onion_response_t::write_header().
ssize_t onion_response_write0 | ( | onion_response * | res, |
const char * | data | ||
) |
Writes some data to the response. \0 ended string.
Writes a 0-ended string to the response.
References onion_response_t::onion_response_write().
Referenced by onion_handler_export_local_directory(), onion_handler_export_local_footer_default(), onion_handler_export_local_header_default(), onion_response_write_html_safe(), onion_webdav_handler(), and onion_response_t::write_header().
int onion_response_write_headers | ( | onion_response * | res | ) |
Writes all the header to the given response.
It writes the headers and depending on the method, return OR_SKIP_CONTENT. this is set when in head mode. Handlers should react to this return by not trying to write more, but if they try this object will just skip those writtings.
Explicit calling to this function is not necessary, as as soon as the user calls any write function this will be performed.
As soon as the headers are written, any modification on them will be just ignored.
References onion_response_t::buffer_pos, onion_response_t::code, CONNECTION_CHUNK_ENCODING, CONNECTION_CLOSE, CONNECTION_KEEP_ALIVE, CONNECTION_UPGRADE, onion_request_t::flags, onion_response_t::flags, onion_response_t::headers, ONION_DEBUG0, onion_dict_t::onion_dict_count(), onion_dict_t::onion_dict_preorder(), ONION_ERROR, onion_request_t::onion_request_keep_alive(), onion_response_t::onion_response_code_description(), onion_response_flush(), onion_response_t::onion_response_printf(), onion_response_t::onion_response_write(), OR_CHUNKED, OR_CONNECTION_UPGRADE, OR_HEAD, OR_HEADER_SENT, OR_HTTP11, OR_LENGTH_SET, OR_METHODS, OR_SKIP_CONTENT, onion_response_t::request, onion_response_t::sent_bytes, onion_request_t::session, onion_request_t::session_id, and onion_response_t::write_header().
Referenced by onion_handler_opack_handler(), onion_handler_static_handler(), onion_jpeg_response(), onion_png_response(), onion_response_flush(), onion_response_t::onion_response_free(), onion_response_t::onion_response_write(), onion_shortcut_response_extra_headers(), onion_shortcut_response_file(), onion_webdav_options(), onion_webdav_propfind(), onion_webdav_proppatch(), and onion_websocket_t::onion_websocket_new().
ssize_t onion_response_write_html_safe | ( | onion_response * | res, |
const char * | data | ||
) |
Writes the given string to the res, but encodes the data using html entitiesThe encoding mens that <html> whould become <html>
Writes some data to the response. \0 ended string, and encodes it if necesary into html entities to make it safe.
References onion_html_quote(), onion_low_free(), and onion_response_write0().
static void write_header | ( | onion_response * | res, |
const char * | key, | ||
const char * | value, | ||
int | flags | ||
) |
Helper that is called on each header, and writes the header.
References onion_response_t::onion_response_write(), and onion_response_write0().
Referenced by onion_response_t::onion_response_write_headers().