public function process_response()

in src/OSS/Http/RequestCore.php [784:831]


    public function process_response($curl_handle = null, $response = null)
    {
        // Accept a custom one if it's passed.
        if ($curl_handle && $response) {
            $this->response = $response;
        }

        // As long as this came back as a valid resource or CurlHandle instance...
        if (is_resource($curl_handle) || (is_object($curl_handle) && in_array(get_class($curl_handle),array('CurlHandle','Swoole\Curl\Handler', 'Swoole\Coroutine\Curl\Handle'),true))) {
            // Determine what's what.
            $header_size = curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE);
            $this->response_headers = substr($this->response, 0, $header_size);
            $this->response_body = substr($this->response, $header_size);
            $this->response_code = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
            $this->response_info = curl_getinfo($curl_handle);
            
            if (intval($this->response_code) / 100 != 2 && isset($this->write_file))
            {
                $this->response_headers = $this->response_raw_headers;
                $this->response_body = $this->response_error_body;
            }

            // Parse out the headers
            $this->response_headers = explode("\r\n\r\n", trim($this->response_headers));
            $this->response_headers = array_pop($this->response_headers);
            $this->response_headers = explode("\r\n", $this->response_headers);
            array_shift($this->response_headers);

            // Loop through and split up the headers.
            $header_assoc = array();
            foreach ($this->response_headers as $header) {
                $kv = explode(': ', $header);
                $header_assoc[strtolower($kv[0])] = isset($kv[1]) ? $kv[1] : '';
            }

            // Reset the headers to the appropriate property.
            $this->response_headers = $header_assoc;
            $this->response_headers['info'] = $this->response_info;
            $this->response_headers['info']['method'] = $this->method;
            
            if ($curl_handle && $response) {
                return new ResponseCore($this->response_headers, $this->response_body, $this->response_code);
            }
        }

        // Return false
        return false;
    }