public function applyCookies($cookies)
    {
        $values = [];
        foreach ($cookies as $cookie) {
            if ($cookie->matches($this->url())) {
                $values[$cookie->path()] = $cookie->name() . '=' . $cookie->value();
            }
        }

        $keys = array_map('strlen', array_keys($values));
        array_multisort($keys, SORT_DESC, $values);
        $headers = $this->headers();
        if ($values) {
            $headers['Cookie'] = implode('; ', $values);
        } else {
            unset($headers['Cookie']);
        }
        return $this;
    }