HTTP3: minimal blocking HTTP/3 client over QUIC
Structures
| Name | |
|---|---|
| struct | N_HTTP3_RESPONSE Result of an HTTP/3 exchange. |
Functions
| Name | |
|---|---|
| void | n_http3_response_free(N_HTTP3_RESPONSE * r) Free the heap buffers held by r and zero the struct (safe on NULL / zeroed). |
| int | n_http3_request_ex(const char * method, const char * url, const char * headers, const unsigned char * body, size_t body_len, int timeout_ms, unsigned flags, N_HTTP3_RESPONSE * out) Perform one blocking HTTP/3 request, with request flags. |
| int | n_http3_request(const char * method, const char * url, const char * headers, const unsigned char * body, size_t body_len, int timeout_ms, N_HTTP3_RESPONSE * out) Perform one blocking HTTP/3 request over a fresh QUIC connection. |
| int | n_http3_parse_url(const char * url, char * host, size_t hostsz, char * port, size_t portsz, char * path, size_t pathsz) Split an https URL into host, port and path (pure; available in every build). |
| int | n_http3_get(const char * url, int timeout_ms, N_HTTP3_RESPONSE * out) Convenience wrapper: HTTP/3 GET of url. |
| int | n_http3_available(void ) Report whether HTTP/3 support was compiled into the library. |
Defines
| Name | |
|---|---|
| N_HTTP3_REQ_ALLOW_ILLEGAL_HEADERS n_http3_request_ex flag: send the caller's extra headers WITHOUT the built-in connection-specific / framing filter (so an otherwise-forbidden header such as transfer-encoding, connection or upgrade reaches the wire). |
|
| N_HTTP3_DEFAULT_TIMEOUT_MS Default per-request budget (milliseconds) when the caller passes <= 0. |
|
| N_HTTP3_BODY_CAP Hard cap on the response body kept in memory (bytes). |
Functions Documentation
function n_http3_response_free
void n_http3_response_free(
N_HTTP3_RESPONSE * r
)
Free the heap buffers held by r and zero the struct (safe on NULL / zeroed).
Parameters:
- r The response to release.
function n_http3_request_ex
int n_http3_request_ex(
const char * method,
const char * url,
const char * headers,
const unsigned char * body,
size_t body_len,
int timeout_ms,
unsigned flags,
N_HTTP3_RESPONSE * out
)
Perform one blocking HTTP/3 request, with request flags.
Parameters:
- method The HTTP method (e.g. "GET", "POST"). NULL uses "GET".
- url The absolute https URL. NULL/empty returns -1.
- headers Optional extra request headers as "Name: Value\r\n" lines, or NULL.
- body Optional request body bytes, or NULL.
- body_len Length of
bodyin bytes (0 when none). - timeout_ms Overall budget in ms; <= 0 uses N_HTTP3_DEFAULT_TIMEOUT_MS.
- flags Bitwise OR of N_HTTP3_REQ_* flags (0 for the default, filtered behaviour).
- out Result, zeroed then filled. NULL returns -1.
Return: 0 on a completed exchange (status received), -1 otherwise (out->error set).
As n_http3_request, plus flags. With N_HTTP3_REQ_ALLOW_ILLEGAL_HEADERS the caller's extra headers bypass the connection-specific / framing filter, so a normally-forbidden header (transfer-encoding, connection, upgrade, keep-alive, proxy-connection) is placed on the HTTP/3 request as-is. This is for protocol-conformance and request-smuggling security testing (how an endpoint or a downgrading front-end treats an illegal framing header); pseudo-headers (names starting with ':') are still rejected. n_http3_request is exactly n_http3_request_ex with flags 0.
function n_http3_request
int n_http3_request(
const char * method,
const char * url,
const char * headers,
const unsigned char * body,
size_t body_len,
int timeout_ms,
N_HTTP3_RESPONSE * out
)
Perform one blocking HTTP/3 request over a fresh QUIC connection.
Parameters:
- method The HTTP method (e.g. "GET", "POST"). NULL uses "GET".
- url The absolute https URL. NULL/empty returns -1.
- headers Optional extra request headers as "Name: Value\r\n" lines, or NULL.
- body Optional request body bytes, or NULL.
- body_len Length of
bodyin bytes (0 when none). - timeout_ms Overall budget in ms; <= 0 uses N_HTTP3_DEFAULT_TIMEOUT_MS.
- out Result, zeroed then filled. NULL returns -1.
Return: 0 on a completed exchange (status received), -1 otherwise (out->error set).
Resolves the host, opens a QUIC connection with ALPN "h3", sends the request, and collects the response. On success out->status is set and out->error is NULL; on failure the function returns -1 and out->error holds the reason. The caller always frees out with n_http3_response_free.
function n_http3_parse_url
int n_http3_parse_url(
const char * url,
char * host,
size_t hostsz,
char * port,
size_t portsz,
char * path,
size_t pathsz
)
Split an https URL into host, port and path (pure; available in every build).
Parameters:
- url The absolute URL (must start with "https://"). NULL returns -1.
- host Out buffer for the host. May be NULL to skip.
- hostsz Size of
host. - port Out buffer for the port (decimal string). May be NULL to skip.
- portsz Size of
port. - path Out buffer for the path (with a leading '/'). May be NULL to skip.
- pathsz Size of
path.
Return: 0 on success, -1 on a malformed URL or a too-small buffer.
Only the https scheme is accepted. When the URL omits the port, "443" is written. When it omits the path, "/" is written. IPv6 literals in brackets are accepted and the brackets are stripped from the host.
function n_http3_get
int n_http3_get(
const char * url,
int timeout_ms,
N_HTTP3_RESPONSE * out
)
Convenience wrapper: HTTP/3 GET of url.
Parameters:
- url The absolute https URL. NULL/empty returns -1.
- timeout_ms Overall budget in ms; <= 0 uses the default.
- out Result (see n_http3_request). NULL returns -1.
Return: 0 on a completed exchange, -1 otherwise.
function n_http3_available
int n_http3_available(
void
)
Report whether HTTP/3 support was compiled into the library.
Return: 1 when built with HAVE_HTTP3 (n_http3_request can run), 0 otherwise.
Macros Documentation
define N_HTTP3_REQ_ALLOW_ILLEGAL_HEADERS
#define N_HTTP3_REQ_ALLOW_ILLEGAL_HEADERS 1u
n_http3_request_ex flag: send the caller's extra headers WITHOUT the built-in connection-specific / framing filter (so an otherwise-forbidden header such as transfer-encoding, connection or upgrade reaches the wire).
For protocol-conformance and request-smuggling security testing of how an HTTP/3 endpoint or a downgrading front-end handles an illegal framing header. Pseudo-headers (a name starting with ':') are still rejected. Use only against authorized targets.
define N_HTTP3_DEFAULT_TIMEOUT_MS
#define N_HTTP3_DEFAULT_TIMEOUT_MS 15000
Default per-request budget (milliseconds) when the caller passes <= 0.
define N_HTTP3_BODY_CAP
#define N_HTTP3_BODY_CAP (16u * 1024u * 1024u)
Hard cap on the response body kept in memory (bytes).
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB