Headers can be used to send information about the request, the client, and more.
Read-Only#
The request headers are read-only and cannot be modified. This is by design, as the headers should be read-only to ensure that the request is not tampered with.
Accessing the Headers#
Via Context#
The headers of the request can be accessed through the request property in the context of the Lifecycle Components.
final headers = context.request.headers;
Via Binding#
The headers of the request can be accessed via the lifecycle method or controller's endpoint by adding the
ReadOnlyHeaders parameter.
@Get()
Future<void> helloWorld(
Header() final String headerName,
) async {
...
}