int get_cookies_from_headers()

in net/http/cookie_jar.cpp [61:119]


    int get_cookies_from_headers(Message* message)  {
        auto r = message->headers.equal_range("Set-Cookie");
        for (auto it = r.first; it != r.second; ++it) {
            auto Cookies = it.second();
            Parser p(Cookies);
            auto key = Cookies | p.extract_until_char('=');
            if (key.size() == 0) continue;
            auto value = Cookies | p.extract_until_char(';');
            if (value.size() == 0) continue;
            p.skip_spaces();
            bool HttpOnly = false;
            bool Partitioned = false;
            bool Secure = false;
            char SameSite = 0;
            uint64_t expire = -1ULL;
            estring_view Path, Domain;
            while(!p.is_done()) {
                auto attr = Cookies | p.extract_until_char(';');
                p.skip_spaces();
                Parser ap(attr);
                auto k2 = attr | ap.extract_until_char('=');
                auto v2 = attr | ap.extract_until_char('\0');
                if (k2 == "Max-Age") {
                    if (uint64_t age = v2.to_uint64()) expire = time(0) + age;
                    else LOG_DEBUG("invalid integer format for 'Max-Age': ", v2);
                } else if (k2 == "Expires") {
                    struct tm tm;
                    auto ok = strptime(v2.data(), "%a, %d %b %Y %H:%M:%S", &tm);
                    if (!ok) LOG_DEBUG("invalid time format for 'Expires': ", v2);
                    else expire = mktime(&tm);
                }
                else if (k2 == "SameSite" && v2.size() > 0) SameSite = v2[0];
                else if (k2 == "Path") Path = v2;
                else if (k2 == "Domain") Domain = v2;
                else if (k2 == "Secure") Secure = true;
                else if (k2 == "HttpOnly") HttpOnly = true;
                else if (k2 == "Partitioned") Partitioned = true;
                else LOG_DEBUG("unknown cookie attribute ", attr);
            }
            #define LOG_DEBUG_CONTINUE(...) { LOG_DEBUG(__VA_ARGS__); continue; }
            if (!Secure) {
                if (Partitioned)
                    LOG_DEBUG_CONTINUE(VALUE(Secure), VALUE(Partitioned));
                if (key.starts_with("__Secure-"))
                    LOG_DEBUG_CONTINUE(VALUE(Secure), VALUE(key));
                if (key.starts_with("__Host-") && (!Domain.empty() || Path != '/'))
                    LOG_DEBUG_CONTINUE(VALUE(Secure), VALUE(key), VALUE(Domain), VALUE(Path));
            }
            auto& cookie = m_cookies[key];
            if (value  != cookie.get_value() || Domain != cookie.get_domain() ||
                Path   != cookie.get_path()) cookie.set_contents(value, Domain, Path);
            cookie.expire      = expire;
            cookie.HttpOnly    = HttpOnly;
            cookie.Partitioned = Partitioned;
            cookie.Secure      = Secure;
            cookie.SameSite    = SameSite;
        }
        return 0;
    }