07 / CONTROL
refusal
What a request refused by a middleware receives: 503 for an open breaker, a spent connection budget or a passed deadline, 429 for a rate limit, 413 for a body too large. Each is a parameter.
WHERE IT SITS
INTERFACE
struct RefusalstructThe response a refused request receives: a status, a body, and the headers sent with it.
let plain_text : Array[(String, String)] = [letThe headers a refusal carries unless told otherwise.
fn Refusal::new( status~ : Int32 = 503, body~ : Bytes = b"503 Service Unavailable", headers~ : Array[(String, String)] = plain_text) -> RefusalfnBuild a refusal. Left alone it is the 503 Service Unavailable the breaker, the shedder and the connection limiter all answer with.
let refusal : Refusal = Refusal::new()letThe generic refusal: 503 Service Unavailable.
let unavailable : Refusal = refusalletWhat an open breaker, a shed request and a spent connection budget answer with.
let too_many : Refusal = Refusal::new( status=429, body=b"429 Too Many Requests")letWhat a rate-limited request answers with.
let timed_out : Refusal = Refusal::new(body=b"service timeout")letWhat a request past its deadline answers with. timeout middleware answers 503 with this body rather than 504, so that is the default.
let too_large : Refusal = Refusal::new( status=413, body=b"413 Payload Too Large")letWhat an over-large request body answers with.
fn Refusal::events(self : Refusal) -> Array[@moonasgi.Event]fnThe refusal as the ASGI events that send it. A pure value, so a middleware's answer is testable without driving the async transport.