public static function parseHeaders(array $headers)
    {
        $headerGroups = array();
        $headerList = array();

        // Collect matching headers into groups
        foreach ($headers as $line) {
            list($key, $value) = explode(': ', $line, 2);
            if (!isset($headerGroups[$key])) {
                $headerGroups[$key] = array();
            }
            $headerGroups[$key][] = $value;
        }
        
        // Collapse groups
        foreach ($headerGroups as $key => $values) {
            $headerList[$key] = implode(', ', $values);
        }

        return $headerList;
    }