47 n_log(LOG_ERR, "CHECK failed: %s (%s:%d)", #cond, __FILE__, __LINE__); \
59 CHECK(strcmp(host,
"example.com") == 0);
61 CHECK(strcmp(path,
"/a/b?c=d") == 0);
64 CHECK(strcmp(host,
"host.test") == 0);
66 CHECK(strcmp(path,
"/") == 0);
69 CHECK(strcmp(host,
"::1") == 0);
74 CHECK(strcmp(path,
"/") == 0);
89 memset(&r, 0,
sizeof(r));
95int main(
int argc,
char** argv) {
111 printf(
"\n[%zu body bytes]\n", resp.
body_len);
115 n_log(
LOG_NOTICE,
"rebuild the library with HAVE_HTTP3 (ngtcp2 + nghttp3 + OpenSSL QUIC) to enable HTTP/3");
123 if (argc > 2 && strcmp(argv[2],
"illegal") == 0) {
126 n_log(
LOG_NOTICE,
"HTTP/3 + illegal transfer-encoding header -> rv=%d status=%d%s%s",
131 n_log(
LOG_NOTICE,
"pass an https URL to fetch it over HTTP/3, e.g. ex_http3 https://cloudflare-quic.com/ (add 'illegal' to also send a forbidden framing header)");
static int g_fails
test counter
static void test_parse_url(void)
exercise the pure URL parser (runs in every build)
#define CHECK(cond)
tiny assert that keeps going and tallies failures
static void test_request_guards(void)
exercise the request entry points' guards + delegation (deterministic, no network)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
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.
size_t body_len
Number of valid bytes in body.
char * error
Failure reason (heap), or NULL on a completed exchange.
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_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_get(const char *url, int timeout_ms, N_HTTP3_RESPONSE *out)
Convenience wrapper: HTTP/3 GET of url.
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_available(void)
Report whether HTTP/3 support was compiled into the library.
void n_http3_response_free(N_HTTP3_RESPONSE *r)
Free the heap buffers held by r and zero the struct (safe on NULL / zeroed).
#define N_HTTP3_REQ_ALLOW_ILLEGAL_HEADERS
n_http3_request_ex flag: send the caller's extra headers WITHOUT the built-in connection-specific / f...
Result of an HTTP/3 exchange.
Minimal blocking HTTP/3 (over QUIC) client.