示例#1
0
HTTPCookie::HTTPCookie(const NameValueCollection& nvc):
	_version(0),
	_secure(false),
	_maxAge(-1),
	_httpOnly(false)
{
	for (NameValueCollection::ConstIterator it = nvc.begin(); it != nvc.end(); ++it)
	{
		const std::string& name  = it->first;
		const std::string& value = it->second;
		if (icompare(name, "comment") == 0)
		{
			setComment(value);
		}
		else if (icompare(name, "domain") == 0)
		{
			setDomain(value);
		}
		else if (icompare(name, "path") == 0)
		{
			setPath(value);
		}
		else if (icompare(name, "max-age") == 0)
		{
			setMaxAge(NumberParser::parse(value));
		}
		else if (icompare(name, "secure") == 0)
		{
			setSecure(true);
		}
		else if (icompare(name, "expires") == 0)
		{
			int tzd;
			DateTime exp = DateTimeParser::parse(value, tzd);
			Timestamp now;
			setMaxAge((int) ((exp.timestamp() - now) / Timestamp::resolution()));
		}
		else if (icompare(name, "version") == 0)
		{
			setVersion(NumberParser::parse(value));
		}
		else if (icompare(name, "HttpOnly") == 0)
		{
			setHttpOnly(true);
		}
		else
		{
			setName(name);
			setValue(value);
		}
	}
}
示例#2
0
HTTPCookie::HTTPCookie(const NameValueCollection& nvc):
    _version(0),
    _secure(false),
    _maxAge(-1),
    _httpOnly(false)
{
    for (NameValueCollection::ConstIterator it = nvc.begin(); it != nvc.end(); ++it) {
        const std::string& name  = it->first;
        const std::string& value = it->second;

        if (icompare(name, "comment") == 0) {
            setComment(value);
        }
        else if (icompare(name, "domain") == 0) {
            setDomain(value);
        }
        else if (icompare(name, "path") == 0) {
            setPath(value);
        }
        else if (icompare(name, "priority") == 0) {
            setPriority(value);
        }
        else if (icompare(name, "max-age") == 0) {
            throw NotImplementedException("HTTPCookie::HTTPCookie max-age");
        }
        else if (icompare(name, "secure") == 0) {
            setSecure(true);
        }
        else if (icompare(name, "expires") == 0) {
            throw NotImplementedException("HTTPCookie::HTTPCookie expires");
        }
        else if (icompare(name, "version") == 0) {
            throw NotImplementedException("HTTPCookie::HTTPCookie version");
        }
        else if (icompare(name, "HttpOnly") == 0) {
            setHttpOnly(true);
        }
        else {
            setName(name);
            setValue(value);
        }
    }
}