readCookies method

List<Cookie> readCookies(
  1. RequestContext req, {
  2. void onInvalidCookie(
    1. Cookie
    )?,
})

Returns a set of all the incoming cookies that had a valid signature attached. Any cookies without a signature, or with a signature that does not match the provided data, are not included in the output.

If an onInvalidCookie callback is passed, then it will be invoked for each unsigned or improperly-signed cookie.

Implementation

List<Cookie> readCookies(RequestContext req,
    {void Function(Cookie)? onInvalidCookie}) {
  return req.cookies.fold([], (out, cookie) {
    var data = getCookiePayloadAndSignature(cookie.value);
    if (data == null || (data[1] != computeCookieSignature(data[0]))) {
      if (onInvalidCookie != null) {
        onInvalidCookie(cookie);
      }
      return out;
    } else {
      return out..add(cookieWithNewValue(cookie, data[0]));
    }
  });
}