|
cwist
Modern C web framework with libttak runtime
|
lsquic/BoringSSL-based HTTP/3 client for CWIST. More...
#include <cwist/net/http/http3_client.h>#include <cwist/core/mem/alloc.h>#include <cwist/sys/err/cwist_err.h>#include "h3_hdr_out.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>#include <arpa/inet.h>#include <netdb.h>#include <sys/socket.h>#include <sys/uio.h>#include <poll.h>#include <pthread.h>#include <ctype.h>#include <strings.h>#include <openssl/ssl.h>#include <openssl/x509.h>#include <openssl/evp.h>#include <lsquic.h>#include <lsxpack_header.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
| #define | MSG_DONTWAIT 0 |
| #define | H3C_MAX_HEADERS 64 |
| #define | H3C_DECODE_BUF_SIZE 65536 |
Typedefs | |
| typedef struct h3c_stream_ctx | h3c_stream_ctx_t |
| typedef struct h3c_hset | h3c_hset_t |
Functions | |
| cwist_http3_client * | cwist_http3_client_create (void) |
| void | cwist_http3_client_destroy (cwist_http3_client *client) |
| int | cwist_http3_client_set_server (cwist_http3_client *client, const char *host, uint16_t port) |
| Set server address for subsequent requests. | |
| int | cwist_http3_client_set_ca_bundle (cwist_http3_client *client, const char *ca_path) |
| Load CA bundle for TLS certificate verification. | |
| void | cwist_http3_client_set_insecure (cwist_http3_client *client, int enabled) |
| Disable or re-enable TLS certificate verification. | |
| void | cwist_http3_client_set_timeout_ms (cwist_http3_client *client, int timeout_ms) |
| Set request timeout in milliseconds. | |
| void | cwist_http3_client_enable_0rtt (cwist_http3_client *client, int enabled) |
| Enable or disable 0-RTT session resumption. | |
| void | cwist_http3_client_enable_datagrams (cwist_http3_client *client, int enabled) |
| Enable or disable QUIC datagram support (RFC 9221). | |
| cwist_error_t | cwist_http3_client_request (cwist_http3_client *client, const char *path, cwist_http_method_t method, cwist_http_header_node *headers, const char *body, size_t body_len, cwist_http_response **out_response) |
| Perform a synchronous HTTP/3 request. | |
| int | cwist_http3_client_send_datagram (cwist_http3_client *client, const void *data, size_t len) |
| Send an unreliable QUIC datagram. | |
| ssize_t | cwist_http3_client_recv_datagram (cwist_http3_client *client, void *buf, size_t len) |
| Receive an unreliable QUIC datagram. | |
| void | cwist_http3_client_set_max_retries (cwist_http3_client *client, int max_retries) |
| Set the maximum number of request retries on transient failure. | |
| void | cwist_http3_client_set_retry_delay_ms (cwist_http3_client *client, int delay_ms) |
| Set the base delay between retries in milliseconds. | |
| void | cwist_http3_client_set_conn_timeout_ms (cwist_http3_client *client, int timeout_ms) |
| Set the connection establishment / stream creation timeout. | |
lsquic/BoringSSL-based HTTP/3 client for CWIST.
Definition in file http3_client.c.
Definition at line 12 of file http3_client.c.
| #define H3C_DECODE_BUF_SIZE 65536 |
Definition at line 208 of file http3_client.c.
| #define H3C_MAX_HEADERS 64 |
Definition at line 207 of file http3_client.c.
| #define MSG_DONTWAIT 0 |
Definition at line 51 of file http3_client.c.
| typedef struct h3c_hset h3c_hset_t |
| typedef struct h3c_stream_ctx h3c_stream_ctx_t |
| cwist_http3_client * cwist_http3_client_create | ( | void | ) |
Definition at line 784 of file http3_client.c.
References cap, SSL_CTX_free, SSL_CTX_new, SSL_CTX_set_default_verify_paths, SSL_CTX_set_min_proto_version, SSL_CTX_set_verify, SSL_VERIFY_PEER, and TLS1_3_VERSION.
| void cwist_http3_client_destroy | ( | cwist_http3_client * | client | ) |
Definition at line 870 of file http3_client.c.
References cap, and SSL_CTX_free.
Enable or disable 0-RTT session resumption.
When enabled, the client attempts to send application data in the first flight if a previous session ticket is available.
| client | Client handle. |
| enabled | Non-zero to enable (default: 0). |
Definition at line 924 of file http3_client.c.
References cap.
Enable or disable QUIC datagram support (RFC 9221).
When enabled, unreliable datagrams can be sent and received via cwist_http3_client_send_datagram() / recv_datagram().
| client | Client handle. |
| enabled | Non-zero to enable (default: 0). |
Definition at line 929 of file http3_client.c.
Receive an unreliable QUIC datagram.
Non-blocking. If no datagram is available, returns -1 with errno set to EAGAIN.
| client | Client handle. |
| buf | Buffer to store payload. |
| len | Buffer capacity. |
Definition at line 1185 of file http3_client.c.
References cap.
| cwist_error_t cwist_http3_client_request | ( | cwist_http3_client * | client, |
| const char * | path, | ||
| cwist_http_method_t | method, | ||
| cwist_http_header_node * | headers, | ||
| const char * | body, | ||
| size_t | body_len, | ||
| cwist_http_response ** | out_response | ||
| ) |
Perform a synchronous HTTP/3 request.
Establishes a QUIC connection if none exists, sends the request, and blocks until the complete response is received or the timeout expires.
| client | Client handle. |
| path | Request path (e.g. "/index.html"). |
| method | HTTP method enum. |
| headers | Optional request headers (may be NULL). |
| body | Optional request body (may be NULL). |
| body_len | Length of body. |
| out_response | Output pointer for parsed response. |
Definition at line 937 of file http3_client.c.
References cap, CWIST_ERR_INT16, cwist_http_response_destroy(), make_error(), and cwist_http_header_node::next.
Send an unreliable QUIC datagram.
Requires datagrams to be enabled. The datagram is delivered on a best-effort basis and may be silently dropped by the network.
| client | Client handle. |
| data | Datagram payload. |
| len | Payload length. |
Definition at line 1162 of file http3_client.c.
References cap.
Load CA bundle for TLS certificate verification.
| client | Client handle. |
| ca_path | Path to PEM CA bundle, or NULL to reload the system default trust store. Verification stays enabled either way; use cwist_http3_client_set_insecure() to opt out. |
Definition at line 904 of file http3_client.c.
References cap, and SSL_CTX_set_default_verify_paths.
Set the connection establishment / stream creation timeout.
This controls how long the client waits for the QUIC handshake and stream creation before giving up. Default is 5000 ms.
| client | Client handle. |
| timeout_ms | Timeout in milliseconds. |
Definition at line 1214 of file http3_client.c.
Disable or re-enable TLS certificate verification.
Verification is ON by default. Opt out explicitly for self-signed development setups; opting out trusts any server certificate.
| client | Client handle. |
| enabled | Non-zero to disable verification (default: 0). |
Definition at line 915 of file http3_client.c.
References cap, SSL_CTX_set_verify, SSL_VERIFY_NONE, and SSL_VERIFY_PEER.
Set the maximum number of request retries on transient failure.
When a request fails due to timeout or connection loss, the client will retry up to max_retries times with exponential backoff. Default is 0 (no retries).
| client | Client handle. |
| max_retries | Maximum retry count (0 to disable). |
Definition at line 1206 of file http3_client.c.
Set the base delay between retries in milliseconds.
The actual delay is doubled on each retry (1x, 2x, 4x, ...). Default is 1000 ms.
| client | Client handle. |
| delay_ms | Base delay in milliseconds. |
Definition at line 1210 of file http3_client.c.
References cap.
Set server address for subsequent requests.
| client | Client handle. |
| host | Server hostname (used for SNI and :authority). |
| port | Server UDP port. |
Definition at line 894 of file http3_client.c.
References cap.
Set request timeout in milliseconds.
| client | Client handle. |
| timeout_ms | Timeout, 0 for default (30000). |
Definition at line 920 of file http3_client.c.