getHeader abstract method

String? getHeader(
  1. String name
)

Retrieves the value of the specified HTTP request header.

HTTP headers are case-insensitive, so getHeader("content-type") and getHeader("Content-Type") will return the same value.

Parameters

  • name: The name of the HTTP header to retrieve

Returns

The header value as a string, or null if the header is not present

Common Headers

  • "Accept": Content types the client can understand
  • "Content-Type": Media type of the request body
  • "User-Agent": Client application identification
  • "Authorization": Authentication credentials
  • "Accept-Language": Preferred languages for response

Example

final contentType = context.getHeader("Content-Type");
final userAgent = context.getHeader("User-Agent");
final authToken = context.getHeader("Authorization");

if (contentType?.contains("application/json") ?? false) {
  // Handle JSON content
}

Implementation

String? getHeader(String name);