RequestId class final

Gives every request an id, and echoes it back.

An inbound x-request-id is kept, so an id assigned by a proxy or an upstream service survives instead of being replaced — but only when it looks like an id. An inbound value is client-controlled and ends up in the response, the access log, and whatever reads that log, so an unchecked one hands a client several kilobytes of your logs per request. Anything longer than maxLength or carrying a character outside A-Z a-z 0-9 - _ . is replaced by a generated id rather than echoed.

final app = Router()..layer(const RequestId());
Implemented types

Constructors

RequestId({String header = 'x-request-id', String generate()?, int maxLength = 128})
Reads or assigns an id, under header.
const

Properties

generate → String Function()?
Builds an id when the request arrived without one.
final
hashCode → int
The hash code for this object.
no setterinherited
The header carrying the id, in and out.
final
maxLength → int
The longest inbound id that is echoed rather than replaced.
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