getCookie function

Cookie? getCookie(
  1. H4Event event,
  2. String name
)

Parameters:

  • event: An H4Event instance containing the HTTP request.
  • name: The name of the cookie to retrieve.

Returns: The cookie with the specified name, or null if not found.

Example:

final authCookie = getCookie(event, 'auth_token');
if (authCookie != null) {
  print('Auth token: ${authCookie.value}');
}

Implementation

Cookie? getCookie(H4Event event, String name) {
  final cookies = event.node["value"]?.cookies;
  if (cookies == null || cookies.isEmpty) return null;

  return cookies.firstWhere(
    (cookie) => cookie.name == name,
  );
}