<commit_before><?php
/**
 * This file is part of the Pipeliner API client library for PHP
 *
 * Copyright 2014 Pipelinersales, Inc. All Rights Reserved.
 * For the full license information, see the attached LICENSE file.
 */

namespace PipelinerSales\ApiClient\Http;

/**
 * Implementation of HttpInterface using cURL to issue the requests.
 */
class CurlHttpClient implements HttpInterface
{

    private $extraCurlOptions = null;
    private $username;
    private $password;
    private $userAgent;

    public function __construct($userAgent = 'Pipeliner_PHP_API_Client/1.0')
    {
        $this->userAgent = $userAgent;
    }

    public function request($method, $url, $rawPayload = null, $contentType = 'application/json')
    {
        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        if (!empty($rawPayload)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $rawPayload);
            curl_setopt(
                $ch,
                CURLOPT_HTTPHEADER,
                array(
                    'Content-Length: ' . strlen($rawPayload),
                    'Content-Type: ' . $contentType
                )
            );
        }

        if (!empty($this->extraCurlOptions)) {
            curl_setopt_array($ch, $this->extraCurlOptions);
        }

        if (!empty($this->username)) {
            curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
        }

        $result = curl_exec($ch);

        if ($result !== false) {
            list($headers, $body) = explode("\r\n\r\n", $result, 2);
        } else {
            list($headers, $body) = array('', '');
        }
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if ($result === false or $status < 200 or $status > 399) {
            throw new PipelinerHttpException(
                new Response($body, $headers, $status, $url, $method),<commit_msg>override curl's Expect header to not get a 100 Continue HTTP response<commit_after><?php
/**
 * This file is part of the Pipeliner API client library for PHP
 *
 * Copyright 2014 Pipelinersales, Inc. All Rights Reserved.
 * For the full license information, see the attached LICENSE file.
 */

namespace PipelinerSales\ApiClient\Http;

/**
 * Implementation of HttpInterface using cURL to issue the requests.
 */
class CurlHttpClient implements HttpInterface
{

    private $extraCurlOptions = null;
    private $username;
    private $password;
    private $userAgent;

    public function __construct($userAgent = 'Pipeliner_PHP_API_Client/1.0')
    {
        $this->userAgent = $userAgent;
    }

    public function request($method, $url, $rawPayload = null, $contentType = 'application/json')
    {
        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        if (!empty($rawPayload)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $rawPayload);
            curl_setopt(
                $ch,
                CURLOPT_HTTPHEADER,
                array(
                    'Content-Length: ' . strlen($rawPayload),
                    'Content-Type: ' . $contentType,
                    'Expect:'
                )
            );
        }

        if (!empty($this->extraCurlOptions)) {
            curl_setopt_array($ch, $this->extraCurlOptions);
        }

        if (!empty($this->username)) {
            curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
        }

        $result = curl_exec($ch);

        if ($result !== false) {
            list($headers, $body) = explode("\r\n\r\n", $result, 2);
        } else {
            list($headers, $body) = array('', '');
        }
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if ($result === false or $status < 200 or $status > 399) {
            throw new PipelinerHttpException(
                new Response($body, $headers, $status, $url, $method),
{'fraction_non_alphanumeric': 0.12690593478770817, 'fraction_numerical': 0.007271874266948158, 'mean_word_length': 2.2926640926640927, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '6642079', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1224, 'n_words': 291}