private function parseHeaders($headers): array {
        if (is_string($headers)) {
            $headers = explode("\r\n", $headers);
        }

        if (empty($headers)) {
            return [];
        }

        $result = [];
        foreach ($headers as $key => $line) {
            if (is_numeric($key)) {
                if (strpos($line, 'HTTP/') === 0) {
                    // Strip the status line and restart.
                    $result = [];
                    continue;
                } elseif (strstr($line, ': ')) {
                    list($key, $line) = explode(': ', $line);
                } else {
                    continue;
                }
            }
            if (is_array($line)) {
                $result[$key] = array_merge($result[$key] ?? [], $line);
            } else {
                $result[$key][] = $line;
            }
        }

        return $result;
    }
private function parseHeaders($headers): array {
        if (is_string($headers)) {
            $headers = explode("\r\n", $headers);
        }

        if (empty($headers)) {
            return [];
        }

        $result = [];
        foreach ($headers as $key => $line) {
            if (is_numeric($key)) {
                if (strpos($line, 'HTTP/') === 0) {
                    // Strip the status line and restart.
                    $result = [];
                    continue;
                } elseif (strstr($line, ': ')) {
                    list($key, $line) = explode(': ', $line);
                } else {
                    continue;
                }
            }
            if (is_array($line)) {
                $result[$key] = array_merge($result[$key] ?? [], $line);
            } else {
                $result[$key][] = $line;
            }
        }

        return $result;
    }
private function parseHeaders ( $ headers ) : array { if ( is_string ( $ headers ) ) { $ headers = explode ( "\r\n" , $ headers ) ; } if ( empty ( $ headers ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ headers as $ key => $ line ) { if ( is_numeric ( $ key ) ) { if ( strpos ( $ line , 'HTTP/' ) === 0 ) { // Strip the status line and restart. $ result = [ ] ; continue ; } elseif ( strstr ( $ line , ': ' ) ) { list ( $ key , $ line ) = explode ( ': ' , $ line ) ; } else { continue ; } } if ( is_array ( $ line ) ) { $ result [ $ key ] = array_merge ( $ result [ $ key ] ?? [ ] , $ line ) ; } else { $ result [ $ key ] [ ] = $ line ; } } return $ result ; }
Parse the http response headers from a response.

@param string|array $headers Either the header string from a curl response or an array of header lines.
@return array
Parse the http response headers from a response .