webtessera/http

Serves a log over the tlog-tiles HTTP API, as a fetch-style handler.

It has no Go counterpart: it is an addition of webtessera’s. Its source is src/http/index.ts.

Functions

addErrorResponse
addErrorResponse is the conventional failed answer to POST /add: 503 Service Unavailable with Retry-After: 1 when the appender pushes back (ErrPushback, which tells the client to slow down rather than give up), as upstream's personalities answer, 405 Method Not Allowed with Allow: POST when readEntryBody refused a request that was not a POST (ErrMethodNotAllowed), and 500 otherwise.
addResponse
addResponse is the conventional successful answer to POST /add: 200 OK with the assigned index as a bare decimal and no trailing newline, which is what upstream's personalities write with fmt.Fprintf(w, "%d", idx.Index).
combineHandlers
combineHandlers returns a fetch-style function that asks each handler in turn and answers with the first response, or with 404 Not Found if none of them owns the request.
newLogHandler
newLogHandler returns a Handler that serves a log over the tlog-tiles read API: GET and HEAD on <prefix>/checkpoint, <prefix>/tile/<L>/<N>.p/<W> and <prefix>/tile/entries/<N>.p/<W>.
parseLogPath
parseLogPath parses a path relative to the log's prefix, with no leading slash: checkpoint, tile/<L>/<N>.p/<W> or tile/entries/<N>.p/<W>.
readEntryBody
readEntryBody reads the entry a POST /add request carries, streaming it and giving up as soon as it exceeds maxBytes (MaxEntryBytes by default, and never more), so that an oversized upload is never buffered.
resourceHeaders
resourceHeaders returns the Content-Type and Cache-Control headers the tlog-tiles spec prescribes for the resource at path (relative to the log's prefix, with no leading slash), or undefined if path is not a tlog-tiles resource.
resourcePath
resourcePath returns the path of r relative to the log's prefix, with no leading slash.
toNodeListener
toNodeListener adapts a Fetch API handler (a Handler, or anything that takes a Request and resolves to a Response) to the callback Node's http.createServer and https.createServer take.

Interfaces

AddErrorResponseOptions
AddErrorResponseOptions configures addErrorResponse.
CacheControlPolicy
CacheControlPolicy holds the Cache-Control values served for the three kinds of resource whose caching differs.
CorsOptions
CorsOptions configures the CORS headers a handler adds when asked to.
LogHandlerOptions
LogHandlerOptions configures newLogHandler.
MalformedPath
MalformedPath is what parseLogPath returns for a path inside the tlog-tiles namespace (tile/...) that is not a well-formed resource path.
NodeIncomingMessage
NodeIncomingMessage is the part of Node's http.IncomingMessage the adapter reads: the request line, the headers and the body, which Node exposes as an async iterable of chunks.
NodeListenerOptions
NodeListenerOptions configures toNodeListener.
NodeServerResponse
NodeServerResponse is the part of Node's http.ServerResponse the adapter writes.

Types

Handler
Handler answers the requests it owns and returns undefined for every other one, so that handlers compose: a log, a witness and an application's own routes can share one server without any of them knowing about the others.
LogResource
LogResource is one resource of the tlog-tiles read API.
LogResourceReader
LogResourceReader is the part of a LogReader the handler reads from.

Constants and variables

CheckpointContentType
CheckpointContentType is the media type the spec gives the checkpoint.
DefaultCacheControl
DefaultCacheControl is the caching policy the spec asks for.
ErrMethodNotAllowed
ErrMethodNotAllowed is the cause of the error readEntryBody throws for a request that is not a POST. addErrorResponse answers it with 405 Method Not Allowed and Allow: POST.
MaxEntryBytes
MaxEntryBytes is the largest entry a tlog-tiles log can hold: entry bundles prefix each entry with its length as a big-endian uint16, which a larger entry would overflow.
MaxResourcePathLength
MaxResourcePathLength bounds the length of a path parseLogPath will parse.
TileContentType
TileContentType is the media type the spec gives tiles and entry bundles.