serp-spider / core

:spider: The PHP SERP Spider - A search engine scraper
https://serp-spider.github.io/
Other
89 stars 44 forks source link

Fix parse of expires from the Set-Cookie HTTP header #13

Closed RubtsovAV closed 7 years ago

RubtsovAV commented 8 years ago

In Cookie instance the expires must contain a unix timestamp, but if you use SetCookieString::parse() in the expires was a time string in gmt format. This is PR fix that.

gsouf commented 8 years ago

Please, can you tell me the reason to use the expire value as a timestamp ? Cookie expiration value must be in international standard format (02-Dec-2016 07:19:25 GMT)

RubtsovAV commented 8 years ago

Because the Cookie class expect expires as unix timestamp.

/**
     * Check if the cookie is expired
     *
     * @return bool
     */
    public function isExpired()
    {
        return $this->getExpires() && time() > $this->getExpires();
    }

Also the ArrayCookieJar use a cookie expires as unix timestamp too.

/**
     * @inheritdoc
     */
    public function removeExpired()
    {
        $currentTime = time();
        $this->cookies = array_filter($this->cookies, function (Cookie $cookie) use ($currentTime) {
            return !$cookie->getExpires() || $currentTime < $cookie->getExpires();
        });
        return $this;
    }

And the CookieFile class for http-client-curl to expect it too.

RubtsovAV commented 8 years ago

Even SetCookie class sets expire as a Unix timestamp, but only if the specified by max-age.

if (!$data['expires'] && $data['max_age']) {
    $data['expires'] = time() + (int) $data['max_age'];
}
gsouf commented 8 years ago

Indeed their are some mistake in the way expires is used, let me think about it, I'm not available atm

gsouf commented 7 years ago

Thanks for your contribution and sorry for the delay for merging