|
cwist
Modern C web framework with libttak runtime
|
HTTPS/TLS wrapper interface. More...
#include <cwist/http.h>#include <cwist/err/cwist_err.h>#include <openssl/ssl.h>#include <openssl/err.h>
Go to the source code of this file.
Classes | |
| struct | cwist_https_context |
| struct | cwist_https_connection |
Typedefs | |
| typedef struct cwist_https_context | cwist_https_context |
| typedef struct cwist_https_connection | cwist_https_connection |
Functions | |
| cwist_error_t | cwist_https_init_context (cwist_https_context **ctx, const char *cert_path, const char *key_path) |
| void | cwist_https_destroy_context (cwist_https_context *ctx) |
| Free an HTTPS context and release its OpenSSL resources. | |
| cwist_error_t | cwist_https_accept (cwist_https_context *ctx, int client_fd, cwist_https_connection **conn) |
| void | cwist_https_close_connection (cwist_https_connection *conn) |
| cwist_http_request * | cwist_https_receive_request (cwist_https_connection *conn) |
| Read from the TLS stream until a full HTTP request has been assembled. | |
| cwist_error_t | cwist_https_send_response (cwist_https_connection *conn, cwist_http_response *res) |
| Serialize an HTTP response and send it over an active TLS connection. | |
| cwist_error_t | cwist_https_server_loop (int server_fd, cwist_https_context *ctx, void(*handler)(cwist_https_connection *conn, void *), void *user_ctx) |
HTTPS/TLS wrapper interface.
Definition in file https.h.
| cwist_error_t cwist_https_accept | ( | cwist_https_context * | ctx, |
| int | client_fd, | ||
| cwist_https_connection ** | conn | ||
| ) |
Perform SSL handshake on an accepted socket. Returns a new cwist_https_connection wrapper.
Definition at line 1756 of file https.c.
References cap, CWIST_ERR_INT16, CWIST_HTTP_TIMEOUT_MS, CWIST_HTTPS_HANDSHAKE_TIMEOUT_MS, make_error(), SSL_accept, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE, SSL_free, SSL_get_error, and SSL_set_fd.
| void cwist_https_close_connection | ( | cwist_https_connection * | conn | ) |
Close and free the HTTPS connection.
Definition at line 1875 of file https.c.
References cwist_conn_registry_untrack(), and cwist_full_gc_enabled().
| void cwist_https_destroy_context | ( | cwist_https_context * | ctx | ) |
Free an HTTPS context and release its OpenSSL resources.
Destroy the HTTPS context and cleanup OpenSSL.
| ctx | Context to destroy. |
Definition at line 1558 of file https.c.
References cap, cwist_https_context::ctx, cwist_https_context::ctx_lock, cwist_free(), OPENSSL_cleanse, SSL_CTX_free, and cwist_https_context::ticket_key.
Referenced by cwist_app_destroy().
| cwist_error_t cwist_https_init_context | ( | cwist_https_context ** | ctx, |
| const char * | cert_path, | ||
| const char * | key_path | ||
| ) |
Initialize the OpenSSL library and create an SSL context. Loads certificate and private key.
Definition at line 1369 of file https.c.
References cap, and cwist_https_init_context_with_options().
| cwist_http_request * cwist_https_receive_request | ( | cwist_https_connection * | conn | ) |
Read from the TLS stream until a full HTTP request has been assembled.
Read data from the SSL connection and parse it as an HTTP request. Uses cwist_http_parse_request internally.
| conn | Active HTTPS connection wrapper. |
Definition at line 1887 of file https.c.
References cwist_http_request::body, cwist_https_connection::buf_len, cap, cwist_http_request::client_fd, cwist_http_request::content_length, cwist_alloc(), cwist_free(), cwist_full_gc_enabled(), cwist_gc_scope_disown(), CWIST_HTTP_BODY_IDLE_TIMEOUT_MS, CWIST_HTTP_HEADERS_TIMEOUT_MS, CWIST_HTTP_MAX_BODY_SIZE, cwist_http_parse_request(), CWIST_HTTP_READ_BUFFER_SIZE, cwist_http_request_destroy(), CWIST_HTTP_TIMEOUT_MS, cwist_sstring_adopt_len(), cwist_https_connection::fd, cwist_http_request::https_conn, cwist_https_connection::read_buf, cwist_https_connection::ssl, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE, SSL_get_error, SSL_pending, and SSL_read.
| cwist_error_t cwist_https_send_response | ( | cwist_https_connection * | conn, |
| cwist_http_response * | res | ||
| ) |
Serialize an HTTP response and send it over an active TLS connection.
Serialize an HTTP response and send it over the SSL connection. Streams the header block and body separately (zero-copy; no intermediate serialization blob) and supports pointer bodies and file streams.
Zero-copy counterpart of the plaintext send path: the header block is serialized into a stack buffer and written first, then the body is streamed straight from its origin (pointer body, sstring, or file stream) instead of materializing one contiguous heap blob.
| conn | Active HTTPS connection wrapper. |
| res | Response object to serialize. |
Definition at line 2102 of file https.c.
References cwist_http_response::body, cap, cwist_alloc(), CWIST_ERR_INT16, cwist_free(), cwist_http_header_add(), cwist_http_header_get(), CWIST_HTTP_MAX_HEADER_SIZE, cwist_http_serialize_headers(), CWIST_TLS_COALESCE_MAX, cwist_sstring::data, cwist_https_connection::fd, cwist_http_response::file_stream_fd, cwist_http_response::file_stream_len, cwist_http_response::file_stream_offset, cwist_http_response::headers, cwist_https_connection::http3_enabled, cwist_http_response::is_ptr_body, make_error(), cwist_http_response::ptr_body, cwist_http_response::ptr_body_len, cwist_sstring::size, cwist_https_connection::ssl, and cwist_http_response::use_file_stream.
| cwist_error_t cwist_https_server_loop | ( | int | server_fd, |
| cwist_https_context * | ctx, | ||
| void(*)(cwist_https_connection *conn, void *) | handler, | ||
| void * | user_ctx | ||
| ) |
Helper to start a simple HTTPS server loop. Note: The handler receives a cwist_https_connection pointer, not an int fd.