protected function getStatusCode(array $headers)
    {
        $status = 0;
        foreach ($headers as $header) {
            if (preg_match('#^HTTP/(?:[^\s]+)\s(?P<code>\d+)\s#', $header, $match)) {
                $status = (int)$match['code'];
            }
        }
        return $status;
    }