abla/http/event/tls
Generated from source.
Import with import "abla/http/event/tls".
Source: abla/http/event/tls/entry.ab
HttpsEventServerOptions (class)
class HttpsEventServerOptions(
val base: HttpEventServerOptions = httpEventServerOptions(),
// Serve HTTP/2 (ALPN h2, and h2c on plain connections).
val http2: bool = true,
// Serve HTTP/1.1. False makes the port HTTP/2 only: a TLS client that does not pick h2 is refused, a plain connection is taken as h2c whatever it sends first.
val http1: bool = true,
val maximumStreams: int = 100,
val maximumHeaderListBytes: int = 65536,
// A connection that has not finished its TLS handshake after this long is closed.
val handshakeTimeoutMilliseconds: int = 5000,
// The decoded request-header bytes the open HTTP/2 streams of one connection may hold together; a stream past it is refused (REFUSED_STREAM, a client retries).
// A connection can have `maximumStreams` streams open, each with a header list up to `maximumHeaderListBytes`: this bounds their sum.
val maximumHeldHeaderBytes: int = 1048576
)
Configures supported HTTP versions, connection limits and TLS handshake timeouts.
HttpStreamExchange (class)
class HttpStreamExchange(
val id: int,
val method: string,
val path: string,
val query: string,
val headers: array<HttpHeader>,
val peer: SocketPeerAddress?,
var room: int = 0,
var requestBytes: int = 0,
var responded: bool = false,
var requestEnded: bool = false
)
What the server tells a streaming handler about its exchange. room is how many response bytes can be written now, requestBytes how much of the request body has arrived.
HTTP_STREAM_NO_CHANGE (val)
val HTTP_STREAM_NO_CHANGE
Leaves the current request-body flow control unchanged.
HTTP_STREAM_PAUSE (val)
val HTTP_STREAM_PAUSE
Pauses request-body credit until the handler resumes it.
HTTP_STREAM_RESUME (val)
val HTTP_STREAM_RESUME
Resumes request-body credit after a pause.
HTTP_STREAM_PAUSE_FOR_ROOM (val)
val HTTP_STREAM_PAUSE_FOR_ROOM
Pause the request body only if what this step wrote did not fit in the response (the server kept the rest): it is resumed by itself once that is all out. The pattern of an echo or a proxy; deciding from exchange.room instead races with the room that opens while the step is applied.
HttpStreamStep (class)
class HttpStreamStep(
val respond: bool = false,
val status: int = 200,
val headers: array<HttpHeader> = [],
// The response body's size when known (content-length; 0 ends the response), -1 when not.
val length: int = -1,
val write: string = "",
val finish: bool = false,
val trailers: array<HttpHeader> = [],
// HTTP_STREAM_PAUSE: no more credit for the request body until HTTP_STREAM_RESUME.
val pause: int = 0,
val abort: bool = false,
// true: call onWritable once the response has room again (a producer that writes as the client takes it).
val wantWritable: bool = false
)
Describes the response headers, output, flow control or abort to apply to a streaming exchange.
HttpStreamHandler (interface)
interface HttpStreamHandler
Receives streaming HTTP callbacks on the event-loop thread and returns the next step without blocking.
HttpStreamHandler.onRequest (method)
fun onRequest(exchange: HttpStreamExchange): HttpStreamStep
Returns the first step when request headers arrive.
HttpStreamHandler.onData (method)
fun onData(exchange: HttpStreamExchange, chunk: string): HttpStreamStep
Returns the next step after receiving a nonempty request-body chunk.
HttpStreamHandler.onEnd (method)
fun onEnd(exchange: HttpStreamExchange, trailers: array<HttpHeader>): HttpStreamStep
Returns the next step when the request body ends and any trailers are available.
HttpStreamHandler.onWritable (method)
fun onWritable(exchange: HttpStreamExchange): HttpStreamStep
Returns the next step when previously blocked response output has room again.
HttpStreamHandler.onAbort (method)
fun onAbort(exchange: HttpStreamExchange, reason: string): void
Notifies the handler that the exchange ended before completing.
HttpsStreamRoute (class)
class HttpsStreamRoute(val method: string, val path: string, val handler: HttpStreamHandler, val maximumBodyBytes: int)
Binds a method and path to a streaming handler and a request-body limit.
HttpsExchange (class)
class HttpsExchange(
val exchange: HttpStreamExchange,
val slot: int,
val stream: int,
val route: int,
var paused: bool = false,
// Request bytes the handler paused on: credited at the resume.
var held: int = 0,
// Response bytes the handler wrote past the room: sent first.
var pending: string = "",
var finishing: bool = false,
var wantWritable: bool = false,
var resumeOnDrain: bool = false,
var blockedWrite: bool = false,
// HTTP/1.1 (stream 0): the request body's framing (0 none, 1 Content-Length with `reqLeft` to come, 2 chunked with `reqPhase`), the response's (chunked when its length is unknown), and whether the
// connection stays for another request. `discarding`: the response ended before the request did, the rest of the request is thrown away.
var h1: bool = false,
var reqFraming: int = 0,
var reqLeft: int = 0,
var reqPhase: int = 0,
var reqEnded: bool = false,
var chunkedResponse: bool = false,
var headResponse: bool = false,
var responseDone: bool = false,
var keepAlive: bool = true,
var discarding: bool = false,
var requestTrailers: array<HttpHeader> = [],
var trailers: array<HttpHeader> = []
)
One live exchange: where it runs, what is held back for it.
HttpsEventServer (class)
resource class HttpsEventServer(
val handler: (HttpRequest) -> HttpResponse,
val listener: TcpListener,
val poller: SocketPoller,
val options: HttpsEventServerOptions,
val tls: TlsServerConfig?,
val descriptors: array<int>,
val descriptorSlots: array<int>,
val states: array<int>,
val sessions: array<TlsServerSession>,
val h2: array<H2Server>,
val inputs: array<string>,
val outputs: array<string>,
val outputOffsets: array<int>,
val writeWatching: array<bool>,
val requestCounts: array<int>,
val closing: array<bool>,
val lastActivity: array<int>,
val started: array<int>,
val peers: array<SocketPeerAddress?>,
var draining: bool,
var stopped: bool,
var drainDeadline: int,
var pass: int,
// Streaming routes and their live exchanges (registered with streamRoute).
val streamRoutes: array<HttpsStreamRoute> = [],
val exchanges: array<HttpsExchange> = [],
var nextExchange: int = 1,
// Reads that cannot complete the HTTP/1 request yet wait in `tails[slot]`, unjoined, until `needs[slot]` bytes are held, and a chunked request
// is kept in pieces in `chunkStates[slot]`: each read is looked at once, not the whole buffer again (see HttpEventServer).
val needs: array<int> = [],
val tails: array<ByteBuffer> = [],
val chunkStates: array<HttpEventChunkState> = [],
// The clocks of the HTTP/1 request being received and the response being sent, per connection (see HttpEventServerOptions).
val deadlines: HttpEventDeadlines = httpEventDeadlines(),
// The server-wide budget of buffered request bytes, HTTP/1 and HTTP/2 together (see HttpEventServerOptions.maximumBufferedRequestBytes).
val budget: HttpEventBudget = httpEventBudget()
)
Owns the listener, poller and per-connection state for an HTTP event server with optional TLS.
HttpsEventServer.drop (method)
fun drop(): void
Closes the active sockets, poller and listener when the server is dropped.
httpsEventServerTls (fun)
fun httpsEventServerTls(certificatePath: string, privateKeyPath: string, http2: bool = true): TlsServerConfig?
The certificate chain and private key (PEM files, such as an ACME client's fullchain.pem and privkey.pem) as a TLS configuration that offers h2 and http/1.1, or null when either failed to load. Keep it for the life of the server.
httpsEventServerTlsPem (fun)
fun httpsEventServerTlsPem(certificatePem: string, privateKeyPem: string, http2: bool = true): TlsServerConfig?
Loads TLS configuration from PEM bytes and returns null if the certificate or key is invalid.
httpsEventServerTlsPems (fun)
fun httpsEventServerTlsPems(entries: array<TlsServerPem>, http2: bool = true): TlsServerConfig?
As httpsEventServerTlsPem for a server with several certificates, chosen by the client's server name (SNI) and signature algorithms: see tlsServerConfigFromPems (the first entry is the default; a name's ECDSA entry goes before its RSA one). null when entries is empty or any certificate or key fails to load.
httpsEventServer (fun)
fun httpsEventServer(
router: HttpRouter,
address: Ipv4SocketAddress,
tls: TlsServerConfig? = null,
options: HttpsEventServerOptions = HttpsEventServerOptions(),
reusePort: bool = false
): HttpsEventServer
Creates an event server for router dispatch, with startup errors available through the returned server.
httpsEventServerHandler (fun)
fun httpsEventServerHandler(
handler: (HttpRequest) -> HttpResponse,
address: Ipv4SocketAddress,
tls: TlsServerConfig? = null,
options: HttpsEventServerOptions = HttpsEventServerOptions(),
reusePort: bool = false
): HttpsEventServer
Creates an event server with a request callback, with listener and poller errors available through the returned server.
HttpsEventServer.streamRoute (extension fun)
fun HttpsEventServer.streamRoute(method: string, path: string, handler: HttpStreamHandler, maximumStreamBodyBytes: int = 0): void
Serves method path (exactly, no query) with handler. maximumStreamBodyBytes bounds the request body of the route: 0 is no limit (the handler's memory is its own). Routes are read when a connection starts: register them before the first step.
HttpsEventServer.streamStep (extension fun)
fun HttpsEventServer.streamStep(id: int, step: HttpStreamStep): bool
Gives a step to a live exchange from outside the handler's callbacks (see the section above). False when the id is not a live exchange.
HttpsEventServer.port (extension fun)
fun HttpsEventServer.port(): int
Returns the listener's bound port or -1 if the host cannot report it.
HttpsEventServer.activeConnections (extension fun)
fun HttpsEventServer.activeConnections(): int
Returns the number of occupied connection slots.
HttpsEventServer.closeSlot (extension fun)
fun HttpsEventServer.closeSlot(slot: int): void
Closes the socket for a connection slot and releases its server state.
HttpsEventServer.slotHeldBytes (extension fun)
fun HttpsEventServer.slotHeldBytes(slot: int): int
The request bytes a connection holds that no handler has taken yet: HTTP/1 input waiting to be framed, reads held back and the chunked body assembled so far, or, for HTTP/2, the decoded header bytes of its open streams and the body bytes buffered for them. A closed slot holds none.
HttpsEventServer.heldRequestBytes (extension fun)
fun HttpsEventServer.heldRequestBytes(): int
The request bytes held by all open connections, counted afresh: what maximumBufferedRequestBytes limits. Zero when nothing is buffered, whatever came and went.
HttpsRead (class)
class HttpsRead(var bytes: string, var status: int)
---- bytes in and out of a slot, through TLS or plain ---- Returns the bytes read ("" with status 0 for would-block, 1 closed, -1 failed in lastStatus); for TLS: want-write is reported as would-block with the write interest set.
HttpsEventServer.readSlot (extension fun)
fun HttpsEventServer.readSlot(slot: int): void
Processes available bytes for one connection and closes it if reading or protocol handling fails.
HttpsEventServer.writeSlot (extension fun)
fun HttpsEventServer.writeSlot(slot: int): void
Attempts to flush pending output and updates the connection's write interest.
HttpsEventServer.acceptReady (extension fun)
fun HttpsEventServer.acceptReady(): void
Accepts pending connections until the listener would block and assigns each accepted connection a slot.
HttpsEventServer.step (extension fun)
fun HttpsEventServer.step(timeoutMilliseconds: int = 1000): int
Polls once for up to the supplied timeout and returns the number of readiness events handled.
HttpsEventServer.beginDrain (extension fun)
fun HttpsEventServer.beginDrain(): void
Graceful stop: no new connections, HTTP/2 connections get GOAWAY and finish their streams, idle HTTP/1.1 connections close.
HttpsEventServer.stop (extension fun)
fun HttpsEventServer.stop(): void
Begins graceful shutdown, closing the listener and letting active exchanges drain.
HttpsEventServer.forceStop (extension fun)
fun HttpsEventServer.forceStop(): void
Closes all connection slots immediately and marks the server stopped.
HttpsEventServer.drain (extension fun)
fun HttpsEventServer.drain(): int
Stops accepting and services active connections to completion or the drain deadline, then returns zero.
HttpsEventServer.listenError (extension fun)
fun HttpsEventServer.listenError(): int
0 while the server listens; otherwise the errno of the failed bind or listen (98 is an address already in use, 13 no permission, 22 an invalid address), or of the failed poller. A server like that never accepts: run() returns 1 at once.
HttpsEventServer.run (extension fun)
fun HttpsEventServer.run(): int
Services the event loop until shutdown, returning 1 if listener or poller startup failed and zero on normal shutdown.
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.