http2_server

Generated by tinox doc

tinox.core.http2_server, split out of the bundled stdlib as a standalone tinox-central package.

ModuleVersionGroup
hpack (no local docs)1.2.8tinox.core
http_server (no local docs)1.2.9tinox.core

Hello server

import tinox.core.http2_server

class Main
{
    fnc main() -> Int32
    {
        const server: Http2Server = Http2Server::new(8443)
        server.get("/hello", ctx => {
            ctx.response.text("Hello over HTTP/2!")
        })
        server.listen()
        return 0
    }
}

class Http2Conn

* State for one HTTP/2 client connection. * Holds all active streams and both encoder/decoder HPACK tables.

Fields

handleInt64
streamsMap<String, Http2Stream>
recvDynTableHpackDynTable
sendDynTableHpackDynTable
peerMaxFrameSizeInt64
peerInitWindowSizeInt64
lastStreamIdInt64
deadBool Set once a connection error (GOAWAY) was sent: the frame loop stops.
continuationStreamInt64 Stream id whose header block is still open (awaiting CONTINUATION), else 0.
sendWindowInt64 Connection-level send window as announced by WINDOW_UPDATE frames.
openStreamsInt64
sendQueueList<Int64> Streams whose response body is still waiting for flow-control credit, in arrival order.
closedCountInt64

Methods

fn new(handle: Int64) → Http2Conn

class Http2Error

Methods

fn NO_ERROR() → Int64
fn PROTOCOL_ERROR() → Int64
fn INTERNAL_ERROR() → Int64
fn FLOW_CONTROL_ERROR() → Int64
fn STREAM_CLOSED() → Int64
fn FRAME_SIZE_ERROR() → Int64
fn REFUSED_STREAM() → Int64
fn CANCEL() → Int64
fn COMPRESSION_ERROR() → Int64
fn ENHANCE_YOUR_CALM() → Int64

class Http2Flags

Methods

fn END_STREAM() → Int64
fn END_HEADERS() → Int64
fn PADDED() → Int64
fn PRIORITY() → Int64
fn ACK() → Int64

class Http2Frame

* An HTTP/2 frame with its 9-byte fixed header fields and payload. * The payload is a list of raw byte values (Int64, each 0–255).

Fields

lengthInt64
typeInt64
flagsInt64
streamIdInt64
payloadList<Int64>

Methods

fn new(type: Int64, flags: Int64, streamId: Int64, payload: List<Int64>) → Http2Frame

class Http2FrameType

Methods

fn DATA() → Int64
fn HEADERS() → Int64
fn PRIORITY() → Int64
fn RST_STREAM() → Int64
fn SETTINGS() → Int64
fn PUSH_PROMISE() → Int64
fn PING() → Int64
fn GOAWAY() → Int64
fn WINDOW_UPDATE() → Int64
fn CONTINUATION() → Int64

fn tinoxBytesToString(bytes: List<Int64>) → String

fn tinoxSecurityGuard(ctx: HttpContext, routeExists: Int64) → Int64

fn tinoxHttpRequestBodyFromBytes(bytes: List<Int64>) → String

fn tinoxHttpClearBodyBridge() → Nothing

fn tinoxHttpBodyLength(body: String) → Int64

fn tinoxHttpBodySlice(body: String, start: Int64, end: Int64) → List<Int64>

class Http2Server

* HTTP/2 server with a fluent route-registration API identical to HttpServer. * * Handles the full HTTP/2 connection lifecycle per RFC 7540: * connection preface validation, SETTINGS exchange, binary frame I/O, * HPACK decoding for requests and encoding for responses, * multi-stream multiplexing, and graceful GOAWAY shutdown.

Fields

portInt64
routesList<Route>
middlewareList<fnc(HttpContext) -> Bool>
socketHandleInt64
runningBool

Methods

fn new(port: Int64) → Http2Server
fn get(path: String, handler: fnc(HttpContext) -> Nothing) → Http2Server
fn post(path: String, handler: fnc(HttpContext) -> Nothing) → Http2Server
fn put(path: String, handler: fnc(HttpContext) -> Nothing) → Http2Server
fn patch(path: String, handler: fnc(HttpContext) -> Nothing) → Http2Server
fn delete(path: String, handler: fnc(HttpContext) -> Nothing) → Http2Server
fn use(mware: fnc(HttpContext) -> Bool) → Http2Server
fn stop() → Nothing
@Throwsfn listen() → Nothing
* Starts listening and enters the connection accept loop. * Each accepted connection runs on its own task, so one idle client never blocks the others.
fnc serveConnection(server: Http2Server, fd: Int64) → Int64
* Runs one connection to completion on its own task (a static function, because spawn does not * take a this-bound method). Errors are contained here: a failing connection only closes itself.
fn readBytes(wire: Int64, count: Int64) → List<Int64>
fn sendBytes(wire: Int64, bytes: List<Int64>) → Nothing
fn appendBytes(dest: List<Int64>, src: List<Int64>) → Nothing
fn readFrame(conn: Http2Conn) → Http2Frame
fn writeFrame(conn: Http2Conn, frame: Http2Frame) → Nothing
fn sendServerSettings(conn: Http2Conn) → Nothing
fn sendSettingsAck(conn: Http2Conn) → Nothing
fn sendPong(conn: Http2Conn, pingPayload: List<Int64>) → Nothing
fn sendGoaway(conn: Http2Conn, errorCode: Int64) → Nothing
fn sendRstStream(conn: Http2Conn, streamId: Int64, errorCode: Int64) → Nothing
fn connError(conn: Http2Conn, errorCode: Int64) → Nothing
Connection error: GOAWAY with the error code, then the frame loop ends.
fn closeStream(conn: Http2Conn, stream: Http2Stream) → Nothing
Marks a stream closed and drops its buffers; the small stub stays so later frames see "closed".
fn streamError(conn: Http2Conn, stream: Http2Stream, errorCode: Int64) → Nothing
fn processSettings(conn: Http2Conn, frame: Http2Frame) → Nothing
fn hasUpper(name: String) → Bool
fn validHeaderList(headers: List<HpackHeader>, trailer: Bool) → Bool
Returns true if the decoded request (or trailer) header list is well-formed.
fn headerBlockComplete(conn: Http2Conn, stream: Http2Stream) → Nothing
* Called when a header block is complete (END_HEADERS). Decodes it, validates it and, * if the request is already complete (END_STREAM), dispatches it.
fn processHeaders(conn: Http2Conn, frame: Http2Frame) → Nothing
fn processContinuation(conn: Http2Conn, frame: Http2Frame) → Nothing
fn processData(conn: Http2Conn, frame: Http2Frame) → Nothing
fn sendWindowUpdate(conn: Http2Conn, streamId: Int64, increment: Int64) → Nothing
fn processPing(conn: Http2Conn, frame: Http2Frame) → Nothing
fn processPriority(conn: Http2Conn, frame: Http2Frame) → Nothing
fn processRstStream(conn: Http2Conn, frame: Http2Frame) → Nothing
fn processWindowUpdate(conn: Http2Conn, frame: Http2Frame) → Nothing
fn dispatchStream(conn: Http2Conn, stream: Http2Stream) → Nothing
* Decodes a completed stream into an HttpContext, runs middleware and * route matching, then sends the HEADERS + DATA response frames.
fn sendResponse(conn: Http2Conn, stream: Http2Stream, response: HttpResponse) → Nothing
* Encodes an HttpResponse as HTTP/2 HEADERS + DATA frames and sends them. * HEADERS carries the :status pseudo-header plus all response headers. * DATA carries the body (omitted for empty bodies; END_STREAM on HEADERS instead).
fn flushStream(conn: Http2Conn, stream: Http2Stream) → Nothing
Sends as much of the stream's pending body as the connection and stream windows allow.
fn flushSendQueue(conn: Http2Conn) → Nothing
Continues every queued response after a window grew (WINDOW_UPDATE, SETTINGS).
fn handleConnection(fd: Int64) → Nothing
* Manages a single HTTP/2 connection from preface validation through GOAWAY. * * Steps: * 1. Read and validate the 24-byte client connection preface * 2. Send server SETTINGS * 3. Enter the frame-processing loop: * - SETTINGS → update peer params, send ACK * - HEADERS → accumulate header block, dispatch when END_HEADERS + END_STREAM * - CONTINUATION → append to header block, dispatch when END_HEADERS * - DATA → accumulate body, dispatch on END_STREAM * - PING → echo back with ACK flag * - RST_STREAM → mark stream closed * - GOAWAY → graceful shutdown * - WINDOW_UPDATE → acknowledged but not tracked (basic flow control) * 4. Send GOAWAY and close the connection
fn runMiddleware(ctx: HttpContext) → Bool
fn routeExistsFor(ctx: HttpContext) → Int64
fn matchRoute(ctx: HttpContext) → Bool

@Errorclass Http2ServerError

* The HTTP/2 server could not start.

Fields

messageString

class Http2Settings

Methods

fn HEADER_TABLE_SIZE() → Int64
fn ENABLE_PUSH() → Int64
fn MAX_CONCURRENT_STREAMS() → Int64
fn INITIAL_WINDOW_SIZE() → Int64
fn MAX_FRAME_SIZE() → Int64
fn MAX_HEADER_LIST_SIZE() → Int64

class Http2Stream

* Per-stream state for an HTTP/2 connection. * * Accumulates the HPACK-encoded header block across one or more * HEADERS/CONTINUATION frames, and body bytes from DATA frames.

Fields

idInt64
stateString "open" | "half_closed_remote" | "closed"
headerBlockList<Int64>
bodyList<Int64>
endStreamBool
expectingContinuationBool
headersList<HpackHeader> Decoded request header fields (decoded when END_HEADERS arrives, in wire order).
headersDoneBool True once the initial header block is complete; a later HEADERS is a trailer block.
trailerBlockBool
sendWindowInt64
refusedBool Over the concurrent-stream limit: decoded for HPACK state, then answered with RST_STREAM.
outBodyString Response body still to be sent (flow-controlled), with the bytes already written.
outBytesList<Int64> Byte copy of a body that could not be sent at once (the length-aware bridge is only valid right after the handler ran).
bodyLengthInt64
sendOffsetInt64

Methods

fn new(id: Int64, window: Int64) → Http2Stream