C and C++ web framework. http://rapida.vilor.one/docs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.5 KiB

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright 2022 Ivan Polyakov */
/*!
* \file response.h
* \brief Response.
*/
#ifndef RAPIDA_RESPONSE_H_ENTRY
#define RAPIDA_RESPONSE_H_ENTRY
#include "keyval.h"
#include "request.h"
#ifdef __cplusplus
extern "C" {
#endif
/*!
* \brief Response statuses.
*/
enum rpd_res_statuses {
rpd_res_st_continue = 100,
rpd_res_st_switching_protocols = 101,
/*! Experimental, check browser compatibility */
rpd_res_st_early_hints = 103,
rpd_res_st_ok = 200,
rpd_res_st_created = 201,
rpd_res_st_accepted = 202,
rpd_res_st_non_authoritative_info = 203,
rpd_res_st_no_content = 204,
rpd_res_st_reset_content = 205,
rpd_res_st_partial_content = 206,
rpd_res_st_multiple_choices = 300,
rpd_res_st_moved_permanently = 301,
rpd_res_st_found = 302,
rpd_res_st_see_other = 303,
rpd_res_st_not_modified = 304,
rpd_res_st_temp_redirect = 307,
rpd_res_st_perm_redirect = 308,
rpd_res_st_bad_request = 400,
rpd_res_st_unauthorized = 401,
rpd_res_st_payment_required = 402,
rpd_res_st_forbidden = 403,
rpd_res_st_not_found = 404,
rpd_res_st_method_not_allowed = 405,
rpd_res_st_not_acceptable = 406,
rpd_res_st_proxy_auth_required = 407,
rpd_res_st_req_timeout = 408,
rpd_res_st_conflict = 409,
rpd_res_st_gone = 410,
rpd_res_st_length_required = 411,
rpd_res_st_precondition_failed = 412,
rpd_res_st_payload_too_large = 413,
rpd_res_st_uri_too_long = 414,
rpd_res_st_unsupported_media_type = 415,
rpd_res_st_range_not_satisfiable = 416,
rpd_res_st_expectation_failed = 417,
rpd_res_st_i_am_teapot = 418,
rpd_res_st_unprocessable_entity = 422,
rpd_res_st_too_early = 425,
rpd_res_st_upgrade_required = 426,
rpd_res_st_precondition_required = 428,
rpd_res_st_too_many_requests = 429,
rpd_res_st_request_header_fields_too_large = 431,
rpd_res_st_unavailable_for_legal_reasons = 451,
rpd_res_st_internal_server_error = 500,
rpd_res_st_not_implemented = 501,
rpd_res_st_bad_gateway = 502,
rpd_res_st_service_unavailable = 503,
rpd_res_st_gateway_timeout = 504,
rpd_res_st_http_ver_not_supported = 505,
rpd_res_st_variant_also_negotiates = 506,
rpd_res_st_insufficient_storage = 507,
rpd_res_st_loop_detected = 508,
rpd_res_st_not_extended = 510,
rpd_res_st_network_auth_required = 511
};
/*!
* \brief Response data wich will be sent to client.
*/
typedef struct {
enum rpd_res_statuses status; /**< Response status code. */
char *location; /**< Location field. */
char *content_type; /**< Content type. */
char *body; /**< Response body. */
rpd_keyval cookie; /**< Set-Cookie fields. */
} rpd_res;
/*!
2 years ago
* \brief Initialize response data.
*
* \param dest Response instance.
*/
void rpd_res_init(rpd_res *dest);
2 years ago
/*!
* \brief Write response headers to string buffer.
*
* \param dest Destination buffer.
* \param src Response.
*
* \return Status code. 0 is success.
*/
int rpd_res_headers_str(char **dest, const rpd_res *src);
/*!
* \brief Write response to string buffer.
*
* \param dest Destination buffer.
* \param src Response.
*
* \return Status code. 0 is succes.
*/
int rpd_res_str(char **dest, const rpd_res *src);
/*!
* \brief Cleans response instance.
*
* This function will not frees response instance,
* only it's data.
*
* \param res Response instance to cleanup.
*/
void rpd_res_cleanup(rpd_res *res);
#ifdef __cplusplus
}
#endif
#endif /* RAPIDA_RESPONSE_H_ENTRY */