6 n__http3_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_http3.h

Minimal blocking HTTP/3 (over QUIC) client. More...

Structures

Name
struct N_HTTP3_RESPONSE
Result of an HTTP/3 exchange.

Detailed Description

Minimal blocking HTTP/3 (over QUIC) client.

Author: Castagnier Mickael

Version: 1.0

A small blocking HTTP/3 client built on ngtcp2 (QUIC transport) + nghttp3 (HTTP/3 framing and QPACK), using the OpenSSL native QUIC TLS handshake through the ngtcp2 "ossl" crypto shim. It performs a single request/response exchange over a fresh QUIC connection and returns the status, response headers, and body.

The whole implementation is compiled only when the library is built with HAVE_HTTP3 defined (opt-in, because it pulls the ngtcp2/nghttp3/OpenSSL h3 stack). Without it the functions still exist but report that HTTP/3 is not available, so callers link unconditionally and probe with n_http3_available(). The URL parser is a pure helper available in both builds.

Active outbound requests must target only authorized hosts.

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __NILOREA_HTTP3_HEADER
#define __NILOREA_HTTP3_HEADER

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>


#define N_HTTP3_DEFAULT_TIMEOUT_MS 15000
#define N_HTTP3_BODY_CAP (16u * 1024u * 1024u)

#define N_HTTP3_REQ_ALLOW_ILLEGAL_HEADERS 1u

typedef struct N_HTTP3_RESPONSE {
    int status;          
    char* headers;       
    unsigned char* body; 
    size_t body_len;     
    char* error;         
} N_HTTP3_RESPONSE;

int n_http3_available(void);

int n_http3_parse_url(const char* url, char* host, size_t hostsz, char* port, size_t portsz, char* path, size_t pathsz);

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);

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);

int n_http3_get(const char* url, int timeout_ms, N_HTTP3_RESPONSE* out);

void n_http3_response_free(N_HTTP3_RESPONSE* r);


#ifdef __cplusplus
}
#endif

#endif /* __NILOREA_HTTP3_HEADER */