API Reference
Complete reference for all exported types, functions, and constants.
Nghttp2Wrapper.HTTP2_PREFACE — Constant
Read one chunk from a TLS connection: either the initial client connection preface (24 bytes) and a following frame, or a single HTTP/2 frame (9-byte header + variable payload).
Nghttp2Wrapper.Callbacks — Type
Callbacks()Create a new nghttp2 callbacks object. Resources are automatically freed when the object is garbage collected, or when close() is called.
Nghttp2Wrapper.ClientContext — Type
Internal context passed as user_data to nghttp2 callbacks.
Nghttp2Wrapper.ConnectionPool — Type
ConnectionPool(; max_per_host=6, idle_timeout=60.0)A pool of HTTP/2 client connections with automatic reuse and keep-alive.
Examples
pool = ConnectionPool()
response = pool_get(pool, "https://nghttp2.org/")
close(pool)Nghttp2Wrapper.HTTP2Client — Type
HTTP2Client(host; port=443, max_concurrent_streams=100,
initial_window_size=65535, header_table_size=4096,
verify_peer=true)Create an HTTP/2 client connected to the given host over TLS. The connection is established immediately with ALPN negotiation for h2.
Nghttp2Wrapper.HTTP2Server — Type
HTTP2Server(handler, port; host="0.0.0.0", certfile="", keyfile="")Create an HTTP/2 server listening on the given port. If certfile and keyfile are provided, the server uses TLS with ALPN h2. Otherwise it uses cleartext HTTP/2 (h2c).
The handler function receives a ServerRequest and returns a ServerResponse.
Examples
Cleartext (h2c):
server = HTTP2Server(8080) do req
ServerResponse(200, "Hello HTTP/2!")
endTLS (h2):
server = HTTP2Server(8443; certfile="cert.pem", keyfile="key.pem") do req
ServerResponse(200, "Hello HTTPS/2!")
endNghttp2Wrapper.HpackDeflater — Type
HpackDeflater(max_table_size::Integer=4096)Create a new HPACK compressor.
Nghttp2Wrapper.HpackInflater — Type
HpackInflater()Create a new HPACK decompressor.
Nghttp2Wrapper.NVPair — Type
NVPair(name, value)An HTTP header name-value pair. Owns copies of the name and value as byte vectors, ensuring memory safety when passed to C functions.
Examples
nv = NVPair(":method", "GET")
nv = NVPair(":path", "/index.html")Nghttp2Wrapper.Nghttp2DataProvider — Type
Layout-compatible representation of nghttp2's nghttp2_data_provider:
typedef union {
int fd;
void *ptr;
} nghttp2_data_source;
typedef struct {
nghttp2_data_source source;
nghttp2_data_source_read_callback read_callback;
} nghttp2_data_provider;We only use the ptr variant of the union, so a single Ptr{Cvoid} for source matches the 8-byte union width on 64-bit platforms.
Nghttp2Wrapper.Nghttp2Error — Type
Nghttp2Error <: ExceptionException thrown when an nghttp2 C function returns an error code.
Fields
code::Cint— the nghttp2 error codemsg::String— human-readable error descriptionfatal::Bool— true if the error is fatal (unrecoverable)
Nghttp2Wrapper.Nghttp2Error — Method
Nghttp2Error(code::Integer)Construct an Nghttp2Error from an error code, automatically filling the message and fatal flag.
Nghttp2Wrapper.Option — Type
Option()Create a new nghttp2 option object for session configuration.
Nghttp2Wrapper.PrioritySpec — Type
PrioritySpec(; dep_stream=0, weight=16, exclusive=false)HTTP/2 stream priority specification.
Fields
dep_stream::Int32— dependent stream ID (0 = root)weight::Int32— priority weight (1-256, default 16)exclusive::Bool— exclusive dependency flag
Nghttp2Wrapper.Request — Type
Request(method, path; headers=NVPair[], body=UInt8[])Represents an outgoing HTTP/2 request.
Fields
method::String— HTTP method (GET, POST, etc.)path::String— Request path (e.g., "/index.html")headers::Vector{NVPair}— Custom request headersbody::Vector{UInt8}— Request body
Nghttp2Wrapper.Response — Type
Response(status, headers, body)Represents an HTTP/2 response.
Fields
status::Int— HTTP status code (e.g., 200, 404)headers::Vector{NVPair}— Response headersbody::Vector{UInt8}— Response body
Nghttp2Wrapper.ResponseBodySource — Type
Response body source passed to nghttp2 via nghttp2_data_provider.
data holds the full response body bytes; offset is the next byte to read. The data source read callback copies up to len bytes into nghttp2's buffer on each invocation, advances offset, and signals NGHTTP2_DATA_FLAG_EOF when offset reaches length(data).
The struct is kept alive across the C boundary by storing it in the owning ServerContext's response_bodies dict (so GC does not reclaim it while nghttp2 still holds a pointer). The dict entry is removed when the callback signals EOF.
Nghttp2Wrapper.ServerContext — Type
Internal context for server-side nghttp2 callbacks.
Nghttp2Wrapper.ServerRequest — Type
ServerRequest(method, path, headers, body, stream_id)Represents an incoming HTTP/2 request as received by a server handler.
Nghttp2Wrapper.ServerResponse — Type
ServerResponse(status; headers=NVPair[], body=UInt8[])
ServerResponse(status, body::AbstractString)
ServerResponse(status, headers, body)Represents an HTTP/2 response to be sent by a server handler.
Nghttp2Wrapper.ServerStreamState — Type
Internal state for a server-side HTTP/2 stream (accumulating a request).
Nghttp2Wrapper.Session — Type
Session(callbacks::Callbacks; server::Bool=false)Create a new HTTP/2 session (client by default, server if server=true). The session holds a reference to the callbacks to prevent premature GC.
Nghttp2Wrapper.StreamState — Type
Internal stream state tracking for an active HTTP/2 stream.
Nghttp2Wrapper._check_open — Method
Check that a wrapper object is still open; throw ArgumentError if closed.
Nghttp2Wrapper._read_tcp_chunk! — Method
Read one chunk from a plain TCP socket: at least one byte, then drain whatever else is immediately available.
Nghttp2Wrapper._server_data_source_read_cb — Method
nghttp2 data source read callback.
Copies up to len bytes from the ResponseBodySource (whose Julia pointer is carried in the source union) into the output buffer that nghttp2 provides. Advances the source's offset, and sets NGHTTP2_DATA_FLAG_EOF in data_flags once the whole body has been consumed.
Matches the C signature:
ssize_t (*nghttp2_data_source_read_callback)(
nghttp2_session *session, int32_t stream_id, uint8_t *buf,
size_t length, uint32_t *data_flags, nghttp2_data_source *source,
void *user_data);Nghttp2Wrapper._server_on_frame_recv_cb — Method
onframerecv callback: dispatches handler when ENDSTREAM is received. The nghttp2frame struct layout: nghttp2framehd (length:sizet, streamid:int32, type:uint8, flags:uint8, ...)
Nghttp2Wrapper._session_send_all — Method
Send all pending data from the session.
Nghttp2Wrapper.acquire — Method
acquire(pool, host; port=443, verify_peer=true) → HTTP2ClientGet a client from the pool. Reuses an idle connection if available, otherwise creates a new one.
Nghttp2Wrapper.check_error — Method
check_error(rv::Integer)Check an nghttp2 return value. If negative, throw Nghttp2Error. Otherwise return rv.
Nghttp2Wrapper.deflate — Method
deflate(d::HpackDeflater, headers::Vector{NVPair}) → Vector{UInt8}Compress headers using HPACK. Returns the compressed bytes.
Nghttp2Wrapper.delete — Method
delete(client, path; headers=NVPair[]) → ResponseNghttp2Wrapper.dynamic_table_size — Method
dynamic_table_size(d::HpackDeflater) → IntReturn the configured maximum dynamic table size for this deflater.
Nghttp2Wrapper.forward_request — Method
forward_request(client::HTTP2Client, req::ServerRequest) → ServerResponseForward a server request to an upstream HTTP/2 server via the client, and return the upstream response as a ServerResponse. Useful for building HTTP/2 proxies.
Nghttp2Wrapper.head — Method
head(client, path; headers=NVPair[]) → ResponseNghttp2Wrapper.inflate — Method
inflate(i::HpackInflater, data::Vector{UInt8}) → Vector{NVPair}Decompress HPACK-encoded headers. Returns a vector of NVPairs.
Nghttp2Wrapper.inspect_dynamic_table — Method
inspect_dynamic_table(d::HpackDeflater) → Vector{NVPair}Return the entries currently in the HPACK dynamic table. Note: This is an approximation — nghttp2 doesn't expose direct dynamic table iteration, so we return the max_size as context information.
Nghttp2Wrapper.listener_port — Method
listener_port(server::HTTP2Server) -> IntReturn the TCP port the server's listening socket is bound to. Works for both plaintext (h2c) and TLS (h2) listeners.
Nghttp2Wrapper.nghttp2_check_authority — Method
nghttp2_check_authority(authority) → BoolCheck if authority is a valid HTTP/2 authority component.
Nghttp2Wrapper.nghttp2_check_header_name — Method
nghttp2_check_header_name(name) → BoolCheck if name is a valid HTTP header field name.
Nghttp2Wrapper.nghttp2_check_header_value — Method
nghttp2_check_header_value(value) → BoolCheck if value is a valid HTTP header field value.
Nghttp2Wrapper.nghttp2_check_method — Method
nghttp2_check_method(method) → BoolCheck if method is a valid HTTP method.
Nghttp2Wrapper.nghttp2_check_path — Method
nghttp2_check_path(path) → BoolCheck if path is a valid HTTP/2 path.
Nghttp2Wrapper.nghttp2_hd_deflate_del — Method
nghttp2_hd_deflate_del(deflater)Free an HPACK deflater.
Nghttp2Wrapper.nghttp2_hd_deflate_hd2 — Method
nghttp2_hd_deflate_hd2(deflater, buf, buflen, nva, nvlen) → Cssize_tCompress headers into buf. Returns the number of bytes written, or a negative error code.
Nghttp2Wrapper.nghttp2_hd_deflate_new — Function
nghttp2_hd_deflate_new(max_deflate_dynamic_table_size=4096) → (Cint, Ptr{Cvoid})Create a new HPACK deflater (compressor).
Nghttp2Wrapper.nghttp2_hd_inflate_del — Method
nghttp2_hd_inflate_del(inflater)Free an HPACK inflater.
Nghttp2Wrapper.nghttp2_hd_inflate_hd2 — Method
nghttp2_hd_inflate_hd2(inflater, nv_out, inflate_flags, data, datalen, in_final) → Cssize_tDecompress headers from data. On each call, check inflate_flags for NGHTTP2_HD_INFLATE_EMIT (header available in nv_out) and NGHTTP2_HD_INFLATE_FINAL (decompression complete).
Nghttp2Wrapper.nghttp2_hd_inflate_new — Method
nghttp2_hd_inflate_new() → (Cint, Ptr{Cvoid})Create a new HPACK inflater (decompressor).
Nghttp2Wrapper.nghttp2_is_fatal — Method
nghttp2_is_fatal(lib_error_code) → BoolReturn true if the given error code is fatal.
Nghttp2Wrapper.nghttp2_option_del — Method
nghttp2_option_del(option)Free an option object.
Nghttp2Wrapper.nghttp2_option_new — Method
nghttp2_option_new() → (Cint, Ptr{Cvoid})Create a new option object. Returns (error_code, option_ptr).
Nghttp2Wrapper.nghttp2_option_set_no_auto_window_update — Method
nghttp2_option_set_no_auto_window_update(option, val)Set the no-auto-window-update option.
Nghttp2Wrapper.nghttp2_option_set_peer_max_concurrent_streams — Method
nghttp2_option_set_peer_max_concurrent_streams(option, val)Set the peer max concurrent streams option.
Nghttp2Wrapper.nghttp2_session_callbacks_del — Method
nghttp2_session_callbacks_del(callbacks)Free a callbacks object.
Nghttp2Wrapper.nghttp2_session_callbacks_new — Method
nghttp2_session_callbacks_new() → (Cint, Ptr{Cvoid})Allocate a new callbacks object. Returns (error_code, callbacks_ptr).
Nghttp2Wrapper.nghttp2_session_callbacks_set_before_frame_send_callback — Method
nghttp2_session_callbacks_set_before_frame_send_callback(callbacks, cb)Set the callback invoked before a frame is sent.
Nghttp2Wrapper.nghttp2_session_callbacks_set_error_callback2 — Method
nghttp2_session_callbacks_set_error_callback2(callbacks, cb)Set the error callback (v2 variant).
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_begin_headers_callback — Method
nghttp2_session_callbacks_set_on_begin_headers_callback(callbacks, cb)Set the callback invoked when reception of a header block begins.
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_data_chunk_recv_callback — Method
nghttp2_session_callbacks_set_on_data_chunk_recv_callback(callbacks, cb)Set the callback invoked when a DATA frame chunk is received.
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_frame_not_send_callback — Method
nghttp2_session_callbacks_set_on_frame_not_send_callback(callbacks, cb)Set the callback invoked when a frame cannot be sent.
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_frame_recv_callback — Method
nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, cb)Set the callback invoked when a frame is received.
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_frame_send_callback — Method
nghttp2_session_callbacks_set_on_frame_send_callback(callbacks, cb)Set the callback invoked after a frame is sent.
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_header_callback — Method
nghttp2_session_callbacks_set_on_header_callback(callbacks, cb)Set the callback invoked when a header name/value pair is received.
Nghttp2Wrapper.nghttp2_session_callbacks_set_on_stream_close_callback — Method
nghttp2_session_callbacks_set_on_stream_close_callback(callbacks, cb)Set the callback invoked when a stream is closed.
Nghttp2Wrapper.nghttp2_session_callbacks_set_recv_callback2 — Method
nghttp2_session_callbacks_set_recv_callback2(callbacks, cb)Set the recv callback (v2 variant using nghttp2_ssize).
Nghttp2Wrapper.nghttp2_session_callbacks_set_send_callback2 — Method
nghttp2_session_callbacks_set_send_callback2(callbacks, cb)Set the send callback (v2 variant using nghttp2_ssize).
Nghttp2Wrapper.nghttp2_session_client_new — Function
nghttp2_session_client_new(callbacks, user_data=C_NULL) → (Cint, Ptr{Cvoid})Create a new client session. Returns (error_code, session_ptr).
Nghttp2Wrapper.nghttp2_session_del — Method
nghttp2_session_del(session)Delete a session and free all associated resources.
Nghttp2Wrapper.nghttp2_session_find_stream — Method
nghttp2_session_find_stream(session, stream_id) → Ptr{Cvoid}Find a stream by its ID. Returns a stream pointer or C_NULL.
Nghttp2Wrapper.nghttp2_session_get_stream_effective_local_window_size — Method
nghttp2_session_get_stream_effective_local_window_size(session, stream_id) → Int32Get the effective local window size for a stream.
Nghttp2Wrapper.nghttp2_session_get_stream_effective_recv_data_length — Method
nghttp2_session_get_stream_effective_recv_data_length(session, stream_id) → Int32Get the effective recv data length for a stream.
Nghttp2Wrapper.nghttp2_session_get_stream_user_data — Method
nghttp2_session_get_stream_user_data(session, stream_id) → Ptr{Cvoid}Get the user data associated with a stream.
Nghttp2Wrapper.nghttp2_session_mem_recv2 — Method
nghttp2_session_mem_recv2(session, data::Vector{UInt8}) → Cssize_tProcess incoming data. Returns the number of bytes processed.
Nghttp2Wrapper.nghttp2_session_mem_send2 — Method
nghttp2_session_mem_send2(session) → (Cssize_t, Ptr{UInt8})Serialize outgoing data from the session into memory. Returns (nbytes, data_ptr) where nbytes is the number of bytes serialized and data_ptr points to the serialized data.
Nghttp2Wrapper.nghttp2_session_server_new — Function
nghttp2_session_server_new(callbacks, user_data=C_NULL) → (Cint, Ptr{Cvoid})Create a new server session. Returns (error_code, session_ptr).
Nghttp2Wrapper.nghttp2_session_set_stream_user_data — Method
nghttp2_session_set_stream_user_data(session, stream_id, user_data) → CintSet the user data associated with a stream.
Nghttp2Wrapper.nghttp2_session_want_read — Method
nghttp2_session_want_read(session) → BoolReturn true if the session wants to receive data from the remote peer.
Nghttp2Wrapper.nghttp2_session_want_write — Method
nghttp2_session_want_write(session) → BoolReturn true if the session wants to send data to the remote peer.
Nghttp2Wrapper.nghttp2_strerror — Method
nghttp2_strerror(lib_error_code) → StringReturn a human-readable string describing the given nghttp2 error code.
Nghttp2Wrapper.nghttp2_submit_goaway — Method
nghttp2_submit_goaway(session, flags, last_stream_id, error_code, opaque_data, opaque_data_len) → CintSubmit a GOAWAY frame.
Nghttp2Wrapper.nghttp2_submit_headers — Method
nghttp2_submit_headers(session, flags, stream_id, pri_spec, nva, nvlen, stream_user_data) → Int32Submit a HEADERS frame.
Nghttp2Wrapper.nghttp2_submit_ping — Method
nghttp2_submit_ping(session, flags, opaque_data) → CintSubmit a PING frame. opaque_data must be a pointer to 8 bytes or C_NULL.
Nghttp2Wrapper.nghttp2_submit_push_promise — Method
nghttp2_submit_push_promise(session, flags, stream_id, nva, nvlen, stream_user_data) → Int32Submit a PUSH_PROMISE frame. Returns the promised stream ID.
Nghttp2Wrapper.nghttp2_submit_request2 — Method
nghttp2_submit_request2(session, pri_spec, nva, nvlen, data_prd, stream_user_data) → Int32Submit a request. Returns the stream ID on success, or a negative error code.
Nghttp2Wrapper.nghttp2_submit_response2 — Method
nghttp2_submit_response2(session, stream_id, nva, nvlen, data_prd) → CintSubmit a response on the given stream.
Nghttp2Wrapper.nghttp2_submit_rst_stream — Method
nghttp2_submit_rst_stream(session, flags, stream_id, error_code) → CintSubmit a RST_STREAM frame.
Nghttp2Wrapper.nghttp2_submit_settings — Method
nghttp2_submit_settings(session, flags, iv, niv) → CintSubmit a SETTINGS frame. iv is a pointer to an array of Nghttp2SettingsEntry and niv is the number of entries.
Nghttp2Wrapper.nghttp2_submit_window_update — Method
nghttp2_submit_window_update(session, flags, stream_id, window_size_increment) → CintSubmit a WINDOW_UPDATE frame.
Nghttp2Wrapper.nghttp2_version — Function
nghttp2_version(least_version=0) → Ptr{Nghttp2Info}Return a pointer to the nghttp2 library version information. If least_version is not 0, returns C_NULL if the library version is less than the specified version.
Nghttp2Wrapper.options — Method
options(client, path; headers=NVPair[]) → ResponseNghttp2Wrapper.patch — Method
patch(client, path; headers=NVPair[], body=UInt8[]) → ResponseNghttp2Wrapper.pool_get — Method
pool_get(pool, url; headers=NVPair[]) → ResponseMake a GET request using a pooled connection.
Nghttp2Wrapper.pool_post — Method
pool_post(pool, url; headers=NVPair[], body=UInt8[]) → ResponseMake a POST request using a pooled connection.
Nghttp2Wrapper.pool_request — Method
pool_request(pool, method, url; headers=NVPair[], body=UInt8[]) → ResponseMake a request using a pooled connection. The URL is parsed to extract host, port, and path. The connection is automatically acquired and released.
Nghttp2Wrapper.post — Method
post(client, path; headers=NVPair[], body=UInt8[]) → ResponseSend an HTTP/2 POST request.
Nghttp2Wrapper.put — Method
put(client, path; headers=NVPair[], body=UInt8[]) → ResponseNghttp2Wrapper.recv! — Method
recv!(session::Session, data::Vector{UInt8}) → IntProcess incoming data. Returns the number of bytes consumed.
Nghttp2Wrapper.release — Method
release(pool, client) → NothingReturn a client to the pool for reuse.
Nghttp2Wrapper.request — Method
request(client, method, path; headers=NVPair[], body=UInt8[]) → ResponseSend an HTTP/2 request and wait for the response. Pseudo-headers (:method, :path, :scheme, :authority) are automatically constructed.
Nghttp2Wrapper.request_stream — Method
request_stream(client, method, path; headers=NVPair[], body=UInt8[]) → (Channel{Response}, Channel{Vector{UInt8}})Send an HTTP/2 request with streaming response body. Returns a done channel and a body chunks channel.
Nghttp2Wrapper.send! — Method
send!(session::Session) → Vector{UInt8}Serialize all pending outgoing data from the session into a byte vector.
Nghttp2Wrapper.set_no_auto_window_update! — Method
set_no_auto_window_update!(opt::Option, val::Bool)Set the no-auto-window-update option.
Nghttp2Wrapper.set_peer_max_concurrent_streams! — Method
set_peer_max_concurrent_streams!(opt::Option, val::Integer)Set the peer max concurrent streams option.
Nghttp2Wrapper.shutdown! — Method
shutdown!(client::HTTP2Client)Initiate graceful shutdown by sending a GOAWAY frame and waiting for all pending streams to complete.
Nghttp2Wrapper.shutdown! — Method
shutdown!(server::HTTP2Server)Gracefully shut down the server: stop accepting new connections, wait for in-flight requests to complete.
Nghttp2Wrapper.submit_goaway! — Method
submit_goaway!(session::Session, last_stream_id::Integer, error_code::Integer)Submit a GOAWAY frame.
Nghttp2Wrapper.submit_ping! — Method
submit_ping!(session::Session)Submit a PING frame.
Nghttp2Wrapper.submit_settings! — Method
submit_settings!(session::Session)
submit_settings!(session::Session, settings::Vector{Nghttp2SettingsEntry})Submit a SETTINGS frame.
Nghttp2Wrapper.to_nghttp2_nv — Method
to_nghttp2_nv(nv::NVPair) → Nghttp2NvConvert an NVPair to the C-compatible Nghttp2Nv struct. The caller MUST ensure the NVPair remains alive (GC.@preserve) for the duration of any C call using the returned struct.
Nghttp2Wrapper.want_read — Method
want_read(session::Session) → BoolReturn true if the session wants to receive data.
Nghttp2Wrapper.want_write — Method
want_write(session::Session) → BoolReturn true if the session wants to send data.
Nghttp2Wrapper.websocket_connect — Method
websocket_connect(client, path; headers=NVPair[]) → Int32Initiate a WebSocket connection over HTTP/2 (RFC 8441) by sending a CONNECT request with the :protocol pseudo-header set to websocket.
Returns the stream ID for the WebSocket tunnel.
Note: Requires server support for RFC 8441 (Extended CONNECT).
Nghttp2Wrapper.with_nva — Method
with_nva(f, pairs::Vector{NVPair})Convert a vector of NVPairs to a C-compatible array of Nghttp2Nv structs, call f(nva_ptr, nvlen), and return the result. The NVPair data is GC-preserved for the duration of the call.