private function extractHeaders($str)
    {
        $this->debug->log(__METHOD__);
        $this->debug->groupUncollapse();
        $headerStart = 0;
        #$this->debug->log(('top', \substr($return, 0, $this->curlInfo['header_size']));
        $headerLenStack = array();
        $i = 0;
        while (true) {
            $headerEnd     = \strpos($str, "\r\n\r\n", $headerStart);
            $headerLength  = $headerEnd - $headerStart;
            $headers       = \substr($str, $headerStart, $headerLength);
            $headerStart   = $headerEnd+4;
            $headerLenStack[] = \strlen($headers)+4;
            #$this->debug->log('headers', \str_replace(array("\r","\n"), array('|','|'), $headers));
            if (\count($headerLenStack) > $this->curlInfo['redirect_count']) {
                #$this->debug->log('header_len_stack','['.\implode(',',$header_len_stack).']');
                $sum = 0;
                for ($j=$i; $j>=0; $j--) {
                    $sum += $headerLenStack[$j];
                    if ($sum == $this->curlInfo['header_size']) {
                        #$this->debug->info('found headers');
                        break 2;
                    }
                }
            }
            if ($headerEnd === false || $i > 20) {
                $this->debug->warn('error parsing headers');
                break;
            }
            $i++;
        }
        // $this->debug->log('headers', $headers);
        return $headers;
    }