abla/http/h2/server
Generated from source.
Import with import "abla/http/h2/server".
Source: abla/http/h2/server/entry.ab
H2_MAX_RESETS_PER_SECOND (val)
val H2_MAX_RESETS_PER_SECOND
The reset-frame count allowed per rate window before the connection closes.
H2_MAX_BUFFERED_BODY_BYTES (val)
val H2_MAX_BUFFERED_BODY_BYTES
Request body bytes buffered for streams whose handler has not run: past it no receive credit is returned until handlers take bodies (RFC 9113 section 5.2: flow control is how a receiver bounds its memory).
H2_REFUSE_OUTPUT_BYTES (val)
val H2_REFUSE_OUTPUT_BYTES
Output queued and unread: new streams are refused at twice the output cap and the connection ends at three times it (a client that never reads).
H2_MAX_HELD_HEADER_BYTES (val)
val H2_MAX_HELD_HEADER_BYTES
The decoded header bytes (names and values, and the request line's) the open streams of one connection hold: a stream whose request would take it past this is refused (REFUSED_STREAM, which a client retries). A header list is bounded per stream, and a connection may have 100 streams open: without this a connection holds 100 lists at once.
H2_MAX_OUTPUT_BYTES (val)
val H2_MAX_OUTPUT_BYTES
The queued output threshold that closes the connection when exceeded.
H2ServerRequest (class)
class H2ServerRequest(val stream: int, val request: HttpRequest)
A request that is whole: the handler's HttpRequest and the stream to answer on.
H2_SERVER_EVENT_REQUEST (val)
val H2_SERVER_EVENT_REQUEST
Streaming routes (streamRoute): a request of one is reported as events instead of waiting to be whole, and its response is written as it is made. REQUEST: the headers are in (request has no body); DATA: a piece of the body (credit for it is given by consumed); END: the request ended (trailers); WRITABLE: writeResponse has room again; RESET: the stream or the connection ended before the exchange did (code, error).
H2_SERVER_EVENT_DATA (val)
val H2_SERVER_EVENT_DATA
Identifies an event carrying a piece of the request body.
H2_SERVER_EVENT_END (val)
val H2_SERVER_EVENT_END
Identifies the end of a streaming request, with any trailers.
H2_SERVER_EVENT_WRITABLE (val)
val H2_SERVER_EVENT_WRITABLE
Identifies a stream whose response can accept more bytes.
H2_SERVER_EVENT_RESET (val)
val H2_SERVER_EVENT_RESET
Identifies a stream or connection reset before the exchange completed.
H2ServerEvent (class)
class H2ServerEvent(val kind: int, val stream: int, val request: HttpRequest? = null, val data: string = "", val trailers: array<HttpHeader> = [], val code: int = 0, val error: string = "")
Carries a streaming request, data, end, writability or reset notification for a stream.
H2_SERVER_STREAM_BODY_CAP (val)
val H2_SERVER_STREAM_BODY_CAP
The response bytes a streamed response holds unsent: writeResponse takes in no more (one stream window).
H2ServerStream (class)
class H2ServerStream(val id: int, var recvWindow: int = 0, var sendWindow: int = 0, var owed: int = 0, var method: string = "", var path: string = "", var query: string = "",
var authority: string = "", var scheme: string = "", var headers: array<HttpHeader> = [], var chunks: array<string> = [], var received: int = 0, var contentLength: int = -1,
var requestDone: bool = false, var sawHeaders: bool = false, var responding: bool = false, var responseBody: string = "", var responsePosition: int = 0, var head: bool = false,
var buffered: int = 0, var abandoned: bool = false,
// The decoded header bytes the stream holds (counted against H2_MAX_HELD_HEADER_BYTES).
var headerBytes: int = 0,
// A streaming route's exchange (streamRoute): `bodyLimit` bytes of request body (0: no limit), the response body written with writeResponse until endResponse (`bodyFinished`), `blocked` a writeResponse
// that took less than it was given, `endSent` the response's END_STREAM is out.
var streaming: bool = false, var bodyLimit: int = 0, var bodyFinished: bool = true, var blocked: bool = false, var endSent: bool = false,
var responseTrailers: array<HttpHeader> = [], var requestTrailers: array<HttpHeader> = [])
Tracks one stream's request, response and flow-control state.
H2Server (class)
class H2Server(
var streams: array<H2ServerStream> = [],
var closedIds: array<int> = [],
var decoder: HpackDecoder,
var encoder: HpackEncoder,
var requests: array<H2ServerRequest> = [],
var output: ByteBuffer,
var outputBytes: int = 0,
var input: string = "",
var peer: SocketPeerAddress? = null,
var prefaceSeen: bool = false,
var peerSeen: bool = false,
var closed: bool = false,
var draining: bool = false,
var error: string = "",
var highestStream: int = 0,
var connectionSend: int = 65535,
var connectionReceive: int = 0,
var connectionOwed: int = 0,
var peerInitialWindow: int = 65535,
var peerMaxFrame: int = 16384,
var maxStreams: int = 100,
var maximumBodyBytes: int = 1048576,
var blockStream: int = 0,
var blockFragments: string = "",
var blockBytes: int = 0,
var blockCount: int = 0,
var blockEndStream: bool = false,
var blockRefused: bool = false,
var quiet: int = 0,
var controlWindowStart: int = 0,
var controlInWindow: int = 0,
var resetWindowStart: int = 0,
var resetsInWindow: int = 0,
var pendingAcks: int = 0,
var settingsAckDeadline: int = -2,
// A response with bytes to send that the peer's flow-control windows hold back for this many ms (counted by tick; 0: never) ends the connection.
var responseTimeout: int = 0,
var stalledSince: int = 0,
var sentBytes: int = 0,
var sentAtStall: int = 0,
var roundRobin: int = 0,
var goawaySent: bool = false,
var now: int = 0,
var bufferedBytes: int = 0,
var overflow: bool = false,
var events: array<H2ServerEvent> = [],
var streamRoutes: array<string> = [],
var streamLimits: array<int> = [],
// The decoded header bytes the open streams may hold together (H2_MAX_HELD_HEADER_BYTES by default; never below one stream's header list).
var maximumHeldHeaderBytes: int = H2_MAX_HELD_HEADER_BYTES,
// Set by the event server while the server-wide budget of request bytes (HttpEventServerOptions.maximumBufferedRequestBytes) is used up: a new stream is refused (REFUSED_STREAM) and no
// receive credit is returned until it is lifted (`budgetRelease`), so a client cannot send more body to a server that has no room.
var budgetFull: bool = false)
Maintains one HTTP/2 server connection and its streams while the caller handles socket I/O.
H2Server.heldBytes (extension fun)
fun H2Server.heldBytes(): int
The request bytes this connection holds for streams whose handler has not run: the decoded header bytes of the open streams and the body bytes buffered for them.
h2ServerNew (fun)
fun h2ServerNew(maximumStreams: int = 100, maximumBodyBytes: int = 1048576, maximumHeaderListBytes: int = 65536, peer: SocketPeerAddress? = null,
maximumHeldHeaderBytes: int = H2_MAX_HELD_HEADER_BYTES): H2Server
A connection with our SETTINGS queued; the peer's preface is expected first. maximumBodyBytes caps a request body, maximumStreams the concurrent streams.
H2Server.takeOutput (extension fun)
fun H2Server.takeOutput(): string
The bytes to write to the peer now (response bodies held back by the output cap are moved into the queue for the next call).
H2Server.wantsWrite (extension fun)
fun H2Server.wantsWrite(): bool
Reports whether encoded frames are waiting to be written.
H2Server.takeRequests (extension fun)
fun H2Server.takeRequests(): array<H2ServerRequest>
Drains and returns the queue of complete requests for non-streaming routes.
H2Server.streamRoute (extension fun)
fun H2Server.streamRoute(method: string, path: string, maximumBodyBytes: int): void
Makes method path (no query) a streaming route: its requests are reported as events (takeEvents) as they arrive and answered with respondStream, writeResponse and endResponse. maximumBodyBytes bounds the request body (0: no limit; a bound the handler enforces itself, or memory it chooses to hold, is its own business).
H2Server.takeEvents (extension fun)
fun H2Server.takeEvents(): array<H2ServerEvent>
The streaming events since the last call (and the connection window's credit for what arrived).
H2Server.consumed (extension fun)
fun H2Server.consumed(stream: int, bytes: int): void
The caller has dealt with bytes of the request body of a streaming stream: its window is credited for them (once half of it was). Not calling it is the pause: the client stalls after one stream window.
H2Server.respondStream (extension fun)
fun H2Server.respondStream(stream: int, status: int, headers: array<HttpHeader>, length: int): bool
Starts the response of a streaming stream: HEADERS now (content-length when length >= 0 and the headers have none; 0 ends the response here, as does a HEAD request), then writeResponse and endResponse. Returns false for a stream that is not a streaming one, was answered already, or a status outside 200..599.
H2Server.writeResponse (extension fun)
fun H2Server.writeResponse(stream: int, chunk: string): int
Writes response body bytes of a streaming stream: returns how many were taken (a prefix of chunk), 0 when it holds a window's worth of unsent bytes already (a WRITABLE event follows when there is room), -1 when the stream is gone, not answered with respondStream, or ended.
H2Server.endResponse (extension fun)
fun H2Server.endResponse(stream: int, trailers: array<HttpHeader> = []): void
The response of a streaming stream is complete: END_STREAM follows what is queued (on a HEADERS frame carrying trailers when there are any).
H2Server.responseRoom (extension fun)
fun H2Server.responseRoom(stream: int): int
The response bytes writeResponse would take now for a streaming stream (0 before respondStream, when it is full, and for a stream that is gone).
H2Server.abortStream (extension fun)
fun H2Server.abortStream(stream: int, code: int): void
The caller gives up on a streaming stream: RST_STREAM(code).
H2Server.isClosed (extension fun)
fun H2Server.isClosed(): bool
Reports whether the connection state machine has closed.
H2Server.openStreams (extension fun)
fun H2Server.openStreams(): int
Returns the number of currently tracked streams.
H2Server.reason (extension fun)
fun H2Server.reason(): string
Why the connection ended ("" while it is open).
H2Server.shutdown (extension fun)
fun H2Server.shutdown(): void
Begins a graceful end: GOAWAY with the highest stream accepted so far; requests already taken are still answered, none new is accepted.
H2Server.finished (extension fun)
fun H2Server.finished(): bool
The connection is over (nothing more to answer): true once a graceful shutdown has no stream left.
H2Server.tick (extension fun)
fun H2Server.tick(now: int): void
Timeouts: our SETTINGS unacknowledged for 10 s; and, when responseTimeout is set, a response held back by the peer's windows for that long.
H2Server.respond (extension fun)
fun H2Server.respond(stream: int, status: int, headers: array<HttpHeader>, body: string): bool
Answers stream: the status, the headers (names are lower-cased; connection-specific ones are dropped) and the body. A HEAD request gets no body. A status outside 200..599 or a stream that is not waiting is ignored (returns false).
H2Server.feed (extension fun)
fun H2Server.feed(data: string, now: int): void
Bytes from the peer: the connection preface first, then frames. Complete frames are processed; a partial one waits for the next call.
H2Server.budgetRelease (extension fun)
fun H2Server.budgetRelease(): void
The server-wide budget has room again: lifts budgetFull and returns the receive credit it held back (the caller sends takeOutput).
h2ValidFieldName (fun)
fun h2ValidFieldName(name: string): bool
Checks for a lowercase HTTP/2 header token with an optional leading pseudo-header colon.
h2ValidFieldValue (fun)
fun h2ValidFieldValue(value: string): bool
RFC 9113 section 8.2.1: a value has no NUL, CR or LF, and does not start or end with a space or tab.
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.