findMaxAgeAttr method

DateTime? findMaxAgeAttr(
  1. String setCookie,
  2. int startIndex,
  3. DateTime now
)

Implementation

DateTime? findMaxAgeAttr(String setCookie, int startIndex, DateTime now) {
  final ai = setCookie.indexOf("Max-Age=", startIndex);
  if (ai == -1) {
    return null;
  }

  final i = ai + 8;
  final j = setCookie.indexOf(';', i);
  final maxAgeStr = j == -1 ? setCookie.substring(i) : setCookie.substring(i, j);
  final maxAge = int.parse(maxAgeStr);

  return now.add(Duration(seconds: maxAge));
}