<commit_before><?php namespace DCarbone\CurlPlus\Response;

/**
 * Class AbstractCurlPlusResponse
 * @package DCarbone\CurlPlus\Response
 */
abstract class AbstractCurlPlusResponse implements ICurlPlusResponse
{
    /** @var string */
    protected $response = null;
    /** @var string */
    protected $responseHeaders = null;
    /** @var array */
    protected $info = null;
    /** @var string */
    protected $error = null;
    /** @var integer */
    protected $httpCode = 404;
    /** @var array */
    protected $curlOpts = array();

    /**
     * Constructor
     *
     * @param string $response
     * @param array $info
     * @param mixed $error
     * @param array $curlOpts
     * @return \DCarbone\CurlPlus\Response\AbstractCurlPlusResponse
     */
    public function __construct($response, $info, $error, array $curlOpts)
    {
        $exp = explode("\r\n\r\n", $response, 2);

        switch(count($exp))
        {
            case 2 :
                $this->response = end($exp);
                $this->responseHeaders = reset($exp);
                break;

            default :
                $this->response = $response;
                break;
        }

        $this->info = $info;
        $this->error = $error;

        if (isset($this->info['http_code']))
            $this->httpCode = (int)$this->info['http_code'];

        $this->curlOpts = $curlOpts;
    }

    /**
     * Get CURL error
     *
     * @name getError
     * @access public
     * @return Mixed
     */
    public function getError()
    {
        return $this->error;
    }

    /**
     * Get CURL info
     *
     * @name getInfo
     * @access public
     * @return array
     */
    public function getInfo()
    {
        return $this->info;
    }

    /**
     * Returns response as string
     *
     * @name __toString
     * @return string  curl response string
     */
    public function __toString()
    {
        return (string)$this->response;
    }

    /**
     * Get the response from the Curl Request
     *
     * @return mixed
     */
    public function getResponse()
    {
        return $this->response;
    }

    /**
     * Return response HTTP code
     *
     * @return int
     */
    public function getHttpCode()
    {
        return $this->httpCode;
    }

    /**
     * @return array|null
     */
    public function getRequestHeaders()
    {
        $info = $this->getInfo();
        return (isset($info['request_header']) ? $info['request_header'] : null);
    }

    /**
     * @return null|string
     */
    public function getResponseHeaders()
    {
        return $this->responseHeaders;
    }
}<commit_msg>Will only attempt to delve response headers from response if CURLOPT_HEADER == true.<commit_after><?php namespace DCarbone\CurlPlus\Response;

/**
 * Class AbstractCurlPlusResponse
 * @package DCarbone\CurlPlus\Response
 */
abstract class AbstractCurlPlusResponse implements ICurlPlusResponse
{
    /** @var string */
    protected $response = null;
    /** @var string */
    protected $responseHeaders = null;
    /** @var array */
    protected $info = null;
    /** @var string */
    protected $error = null;
    /** @var integer */
    protected $httpCode = 404;
    /** @var array */
    protected $curlOpts = array();

    /**
     * Constructor
     *
     * @param string $response
     * @param array $info
     * @param mixed $error
     * @param array $curlOpts
     * @return \DCarbone\CurlPlus\Response\AbstractCurlPlusResponse
     */
    public function __construct($response, $info, $error, array $curlOpts)
    {
        if (array_key_exists(CURLOPT_HEADER, $curlOpts) && $curlOpts[CURLOPT_HEADER] == true)
        {
            $exp = explode("\r\n\r\n", $response, 2);


            switch(count($exp))
            {
                case 2 :
                    $this->response = end($exp);
                    $this->responseHeaders = reset($exp);
                    break;

                default :
                    $this->response = $response;
                    break;
            }
        }
        else
        {
            $this->response = $response;
        }

        $this->info = $info;
        $this->error = $error;

        if (isset($this->info['http_code']))
            $this->httpCode = (int)$this->info['http_code'];

        $this->curlOpts = $curlOpts;
    }

    /**
     * Get CURL error
     *
     * @name getError
     * @access public
     * @return Mixed
     */
    public function getError()
    {
        return $this->error;
    }

    /**
     * Get CURL info
     *
     * @name getInfo
     * @access public
     * @return array
     */
    public function getInfo()
    {
        return $this->info;
    }

    /**
     * Returns response as string
     *
     * @name __toString
     * @return string  curl response string
     */
    public function __toString()
    {
        return (string)$this->response;
    }

    /**
     * Get the response from the Curl Request
     *
     * @return mixed
     */
    public function getResponse()
    {
        return $this->response;
    }

    /**
     * Return response HTTP code
     *
     * @return int
     */
    public function getHttpCode()
    {
        return $this->httpCode;
    }

    /**
     * @return array|null
     */
    public function getRequestHeaders()
    {
        $info = $this->getInfo();
        return (isset($info['request_header']) ? $info['request_header'] : null);
    }

    /**
     * @return null|string
     */
    public function getResponseHeaders()
    {
        return $this->responseHeaders;
    }
}
{'fraction_non_alphanumeric': 0.1302640970735189, 'fraction_numerical': 0.0017844396859386152, 'mean_word_length': 1.7354807223035627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '400563', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1600, 'n_words': 373}