title |
---|
HttpWasm |
Grain API for http-wasm ABI
Implements WASM foreign binding from ./http-wasm-abi.gr
.
Traefik plugin logic code can include HttpWasm
to use native http-wasm functions,
and register functions that will be called when http-wasm's handle_request
or handle_response
are called.
Type declarations included in the HttpWasm module.
record Request {
method: String,
path: String,
headers: List<String>,
sourceAddr: String,
protocolVersion: String,
}
Reguest
is provided as argument to any functions provided to registerRequestHandler
record Response {
headers: List<String>,
}
Response
is provided as argument to any functions provided to registerResponseHandler
type RequestHandler = Request => Bool
type ResponseHandler = Response => Void
enum LogLevel {
Debug,
Info,
Warn,
Err,
}
See http-wasm ABI spec for log_level
enum Features {
BufferRequest,
BufferResponse,
Trailers,
}
See http-wasm ABI spec for features
enum HeaderKind {
RequestHeader,
ResponseHeader,
}
See http-wasm ABI spec for header_kind
Functions and constants included in the HttpWasm module.
enableFeatures : (features: List<Features>) => Void
See http-wasm ABI spec for HttpWasmAbi._log
"whether the next handler on the host flushes the response prior to returning is implementation-specific..."
log : (level: LogLevel, msg: String) => Void
See http-wasm ABI spec for HttpWasmAbi._log
getConfig : () => String
Get middleware dynamic configuration exposed from Traefik as string containing unparsed JSON string
See http-wasm ABI spec for HttpWasmAbi._getConfig
hostJson : Result<Json.Json, Json.JsonParseError>
Grain helper function to parse JSON from Traefik, so not part of http-wasm ABI.
Middleware configuration exposed from Traefik via get_config
, as "raw" Grain Json.Json
types.
configMap : Map.Map<String, String>
Grain helper function to parse JSON from Traefik, so not part of http-wasm ABI
Middleware configuration exposed from Traefik via get_config
, as Grain Map
type.
This can be used like: Map.get("Headers.Foo", configMap)
getConfigItem : (name: String) => Option<String>
Grain helper function to parse JSON from Traefik, so not part of http-wasm ABI
Quick access to config data from plugin.gr
code. For example:
let fooHeaderValue = getConfigItem("Headers.Foo")
getMethod : () => String
See http-wasm ABI spec for HttpWasmAbi._getMethod
getUri : () => String
See http-wasm ABI spec for HttpWasmAbi._getUri
getProtocolVersion : () => String
See http-wasm ABI spec for HttpWasmAbi._getProtocolVersion
getSourceAddr : () => String
See http-wasm ABI spec for HttpWasmAbi._getSourceAddr
getHeaderNames : (headerKind: HeaderKind) => List<String>
See http-wasm ABI spec for HttpWasmAbi._getHeaderNames
getHeaderValues : (headerKind: HeaderKind, name: String) => String
See http-wasm ABI spec for HttpWasmAbi._getHeaderValues
addHeaderValue :
(headerKind: HeaderKind, name: String, value: String) => Void
NOTE** plugin will panic if addHeaderValue()
is called on existing header.
Check getHeaderName()
if header already exists before call addHeaderValue()
.
See http-wasm ABI spec for HttpWasmAbi._addHeaderValue
setHeaderValue :
(headerKind: HeaderKind, name: String, value: String) => Void
NOTE** plugin will panic if setHeaderValue()
is called on non-existing header.
Check getHeaderName()
to make sure header exists before call setHeaderValue()
.
See http-wasm ABI spec for HttpWasmAbi._setHeaderValue
removeHeader : (headerKind: HeaderKind, name: String) => Void
See http-wasm ABI spec for HttpWasmAbi._removeHeader
getStatusCode : () => Int32
NOTE** will panic if status code has not be previously set.
See http-wasm ABI spec for HttpWasmAbi._getStatusCode
registerRequestHandler : (fn: RequestHandler) => Void
This is critical to how plugin.gr
works.** The interface between handle_request
and Grain
Traefik Plugin code is one or more calls to registerRequestHandler
. This module will use
list of "registered handlers" when a call from host (Traefik) to handle_request
is invoked.
All registered functions must return true
or false
to indicate whether HTTP processing should continue.
registerResponseHandler : (fn: ResponseHandler) => Void
handle_request : () => WasmI64
See http-wasm ABI spec for handle_request
handle_response : (high: WasmI32, low: WasmI32) => Void
See http-wasm ABI spec for handle_response
stripNulls : (str: String) => String
Helper to remove C-like null-terminated strings that http-wasm returns.
Returns** String to the null-terminator
Traefik logging seems to ignore them. However Grain
Number.parse()
treats null-terminated string as invalid char.
dumpCodePoints : (str: String) => String
For debugging, dump strings as codepoints to see tailing non-printables