RequestTimeout class final

Gives every request below it a deadline.

Without one, a handler that never completes holds its connection forever. The body limit bounds how much a request can send; this bounds how long it can take.

It bounds producing the response, not sending it. The budget covers the handler returning a Response. A handler that returns immediately with a streamed body — an event stream, a large download — has already satisfied it, and the stream then runs for as long as it likes. Adding this layer above an SSE endpoint protects nothing there, and the connection is held until the stream ends or the client leaves. Bound those in the stream itself, with take, a timeout on the source, or a keep-alive the client answers.

final app = Router()
  ..layer(const RequestTimeout(Duration(seconds: 30)))
  ..merge(routes);
Implemented types

Constructors

RequestTimeout(Duration budget, {void onTimeout(Request request)?})
Fails a request that takes longer than budget.
const

Properties

budget Duration
How long a handler may take.
final
hashCode int
The hash code for this object.
no setterinherited
onTimeout → void Function(Request request)?
Called when the budget runs out, before the 503 goes back.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMiddleware() Middleware
Builds the shelf middleware this value configures.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited