![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
| struct | N_HTTP3_RESPONSE |
| Result of an HTTP/3 exchange. More... | |
Macros | |
| #define | N_HTTP3_BODY_CAP (16u * 1024u * 1024u) |
| Hard cap on the response body kept in memory (bytes). | |
| #define | N_HTTP3_DEFAULT_TIMEOUT_MS 15000 |
| Default per-request budget (milliseconds) when the caller passes <= 0. | |
| #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). | |
Functions | |
| int | n_http3_available (void) |
| Report whether HTTP/3 support was compiled into the library. | |
| int | n_http3_get (const char *url, int timeout_ms, N_HTTP3_RESPONSE *out) |
Convenience wrapper: HTTP/3 GET of 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). | |
| 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_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. | |
| void | n_http3_response_free (N_HTTP3_RESPONSE *r) |
Free the heap buffers held by r and zero the struct (safe on NULL / zeroed). | |
| struct N_HTTP3_RESPONSE |
Result of an HTTP/3 exchange.
Free the inner buffers with n_http3_response_free.
Collaboration diagram for N_HTTP3_RESPONSE:| Data Fields | ||
|---|---|---|
| unsigned char * | body | Response body bytes (NOT NUL-terminated), or NULL. |
| size_t | body_len | Number of valid bytes in body. |
| char * | error | Failure reason (heap), or NULL on a completed exchange. |
| char * | headers | Response header block as joined "name: value\r\n" lines (lowercased names), or NULL. |
| int | status | HTTP status code, or 0 if none was received. |
| #define N_HTTP3_BODY_CAP (16u * 1024u * 1024u) |
| #define N_HTTP3_DEFAULT_TIMEOUT_MS 15000 |
| #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.
| int n_http3_available | ( | void | ) |
| int n_http3_get | ( | const char * | url, |
| int | timeout_ms, | ||
| N_HTTP3_RESPONSE * | out | ||
| ) |
Convenience wrapper: HTTP/3 GET of url.
| 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. |
Definition at line 128 of file n_http3.c.
References n_http3_request().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| 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).
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.
| 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. |
Definition at line 57 of file n_http3.c.
References port.
Referenced by test_parse_url().
Here is the caller graph for this function:| 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.
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.
| 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 body in 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. |
Definition at line 1108 of file n_http3.c.
References N_HTTP3_RESPONSE::error.
Referenced by n_http3_get(), n_http3_request_ex(), and test_request_guards().
Here is the caller graph for this function:| 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.
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.
| 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 body in 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. |
Definition at line 1123 of file n_http3.c.
References n_http3_request().
Referenced by main(), and test_request_guards().
Here is the call graph for this function:
Here is the caller graph for this function:| void n_http3_response_free | ( | N_HTTP3_RESPONSE * | r | ) |
Free the heap buffers held by r and zero the struct (safe on NULL / zeroed).
| r | The response to release. |
Definition at line 43 of file n_http3.c.
References N_HTTP3_RESPONSE::body, N_HTTP3_RESPONSE::body_len, N_HTTP3_RESPONSE::error, N_HTTP3_RESPONSE::headers, and N_HTTP3_RESPONSE::status.
Referenced by main(), and test_request_guards().
Here is the caller graph for this function: