getCookie function
Get a specific cookie by name from the request.
Parameters:
event
: AnH4Event
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,
);
}