protected function parseHeaders($string) 
    {
        $headers = array();
        $lines = explode("\r\n", trim($string));
        foreach($lines as $line) {
            @list($key, $val) = explode(':', $line, 2);
            $key = strtolower(trim($key));
            $val = trim($val);
            if(empty($val)) continue;
            if(isset($headers[$key])) {
                if(is_array($headers[$key])) {
                    $headers[$key][] = $val;
                } else {
                    $headers[$key] = array($headers[$key], $val);
                }
            } else {
                $headers[$key] = $val;
            }
        }
        return $headers;
    }