Initialize a new cURL resource

@return bool
@throws CurlException
183226
public function initialize()
    {
        if ($this->isInitialized())
        {
            $this->close();
        }

        if ( ! ($this->curl = curl_init()))
        {
            throw new CurlException('Could not initialize a cURL resource');
        }

        return true;
    }
608982
public function _curlPrep()
    {
        // Check for required stuff
        if (!isset($this->uri))
            throw new \Exception('Attempting to send a request before defining a URI endpoint.');

        if (isset($this->payload)) {
            $this->serialized_payload = $this->_serializePayload($this->payload);
        }

        if (isset($this->send_callback)) {
            call_user_func($this->send_callback, $this);
        }

        $ch = curl_init($this->uri);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
        if ($this->method === Http::HEAD) {
            curl_setopt($ch, CURLOPT_NOBODY, true);
        }

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

        if ($this->hasClientSideCert()) {

            if (!file_exists($this->client_key))
                throw new \Exception('Could not read Client Key');

            if (!file_exists($this->client_cert))
                throw new \Exception('Could not read Client Certificate');

            curl_setopt($ch, CURLOPT_SSLCERTTYPE,   $this->client_encoding);
            curl_setopt($ch, CURLOPT_SSLKEYTYPE,    $this->client_encoding);
            curl_setopt($ch, CURLOPT_SSLCERT,       $this->client_cert);
            curl_setopt($ch, CURLOPT_SSLKEY,        $this->client_key);
            curl_setopt($ch, CURLOPT_SSLKEYPASSWD,  $this->client_passphrase);
            // curl_setopt($ch, CURLOPT_SSLCERTPASSWD,  $this->client_cert_passphrase);
        }

        if ($this->hasTimeout()) {
            if (defined('CURLOPT_TIMEOUT_MS')) {
                curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 1000);
            } else {
                curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
            }
        }

        if ($this->follow_redirects) {
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
        }

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->strict_ssl);
        // zero is safe for all curl versions
        $verifyValue = $this->strict_ssl + 0;
        //Support for value 1 removed in cURL 7.28.1 value 2 valid in all versions
        if ($verifyValue > 0) $verifyValue++;
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifyValue);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // https://github.com/nategood/httpful/issues/84
        // set Content-Length to the size of the payload if present
        if (isset($this->payload)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload);
            if (!$this->isUpload()) {
                $this->headers['Content-Length'] =
                    $this->_determineLength($this->serialized_payload);
            }
        }

        $headers = array();
        // https://github.com/nategood/httpful/issues/37
        // Except header removes any HTTP 1.1 Continue from response headers
        $headers[] = 'Expect:';

        if (!isset($this->headers['User-Agent'])) {
            $headers[] = $this->buildUserAgent();
        }

        $headers[] = "Content-Type: {$this->content_type}";

        // allow custom Accept header if set
        if (!isset($this->headers['Accept'])) {
            // http://pretty-rfc.herokuapp.com/RFC2616#header.accept
            $accept = 'Accept: */*; q=0.5, text/plain; q=0.8, text/html;level=3;';

            if (!empty($this->expected_type)) {
                $accept .= "q=0.9, {$this->expected_type}";
            }

            $headers[] = $accept;
        }

        // Solve a bug on squid proxy, NONE/411 when miss content length
        if (!isset($this->headers['Content-Length']) && !$this->isUpload()) {
            $this->headers['Content-Length'] = 0;
        }

        foreach ($this->headers as $header => $value) {
            $headers[] = "$header: $value";
        }

        $url = \parse_url($this->uri);
        $path = (isset($url['path']) ? $url['path'] : '/').(isset($url['query']) ? '?'.$url['query'] : '');
        $this->raw_headers = "{$this->method} $path HTTP/1.1\r\n";
        $host = (isset($url['host']) ? $url['host'] : 'localhost').(isset($url['port']) ? ':'.$url['port'] : '');
        $this->raw_headers .= "Host: $host\r\n";
        $this->raw_headers .= \implode("\r\n", $headers);
        $this->raw_headers .= "\r\n";

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        if ($this->_debug) {
            curl_setopt($ch, CURLOPT_VERBOSE, true);
        }

        curl_setopt($ch, CURLOPT_HEADER, 1);

        // If there are some additional curl opts that the user wants
        // to set, we can tack them in here
        foreach ($this->additional_curl_opts as $curlopt => $curlval) {
            curl_setopt($ch, $curlopt, $curlval);
        }

        $this->_ch = $ch;

        return $this;
    }
954886
protected function _init(array $curl_options)
	{
		$options = array(
			CURLOPT_SSL_VERIFYPEER => FALSE,
			CURLOPT_SSL_VERIFYHOST => FALSE,
			CURLOPT_RETURNTRANSFER => TRUE,
			CURLOPT_FOLLOWLOCATION => TRUE,
			CURLOPT_MAXREDIRS      => 10
		);

		$options += $curl_options;

		$curl = curl_init();

		curl_setopt_array($curl, $options);

		return $curl;
	}
1199495
protected function call()
    {
        // Check if the curl object is set
        if (!$this->isInit()) {
            // If it isn't, we do it right now
            $this->init();
        }

        $options = array();
        // Set basic authentication if enabled
        if ($this->authentication instanceof BasicAuthentication) {
            $options['auth'] = array(
                $this->authentication->getUsername(),
                $this->authentication->getPassword()
            );
        }

        $request = $this->getHttpClient()->createRequest(
            $this->getHttpMethod(),
            $this->getEndpoint(),
            array_merge(
                $options,
                array('headers' => $this->getHeaders())
            )
        );

        foreach ($this->getEndpointParameters() as $key => $value) {
            $request->getQuery()->set($key, $value);
        }

        if (($body = $this->getBody()) !== null) {
            $request->setBody(\GuzzleHttp\Stream\Stream::factory($body));
        }

        try {
            $response = $this->getHttpClient()->send($request);
        } catch (ClientException $e) {// Check if not found
            if ($e->getResponse()->getStatusCode() === StatusCodes::HTTP_NOT_FOUND) {
                throw new HttpNotFoundException();
            }

            // Check if unauthorized
            if ($e->getResponse()->getStatusCode() === StatusCodes::HTTP_UNAUTHORIZED) {
                throw new UnauthorizedException();
            }

            throw $e;
        }

        $this->setHttpStatusCode($response->getStatusCode());

        if ($this->getAccept() == 'application/json') {
            $this->setData($response->json());
        } else {
            $this->setData($response->getBody(true));
        }
    }
561498
protected function curl_execute()
    {
        $ch = curl_init();

        curl_setopt_array($ch, $this->getOptions());

        $this->_content = curl_exec($ch);

        $this->_errorCode = curl_errno($ch);

        $this->_info = curl_getinfo($ch);

        if ($this->_errorCode) {
            $this->_errorMessage = curl_error($ch);
        }
        curl_close($ch);
        return $this->isHttpOK();
    }
1237746
public function init()
    {
        $serviceFactory = new \OAuth\ServiceFactory();
        $serviceFactory->setHttpClient(new CurlClient());
        $this->service = $serviceFactory->createService(
            $this->getServiceName(), $this->credentials, $this->sessionStorage, $this->scopes
        );

        return $this;
    }
1364249
public function init(): bool
    {
        $authHeader = $this->request->getHeader('Authorization');

        if (null === $authHeader) {
            $this->errorCode = self::ERR_NOAWSHEADER;

            return false;
        }
        $authHeader = explode(' ', $authHeader);

        if ('AWS' !== $authHeader[0] || !isset($authHeader[1])) {
            $this->errorCode = self::ERR_NOAWSHEADER;

            return false;
        }

        list($this->accessKey, $this->signature) = explode(':', $authHeader[1]);

        return true;
    }
704289
protected function createClient()
    {
        $client = new MultiCurl();

        $credentials     = $this->getCredentials();
        $isAuthenticated = $credentials instanceof SSLCertificate;

        $client->setVerifyPeer($isAuthenticated);

        if ($isAuthenticated) {
            $client->setOption(CURLOPT_SSLCERT, $credentials->getCertificatePassPhrase());
            $client->setOption(CURLOPT_SSLCERTPASSWD, $credentials->getCertificatePassPhrase());
        }

        $this->serviceClient = new Browser($client);

        return $this;
    }
673795
private function configureCurl()
    {
        foreach($this->getCurlOptions() as $option => $value){
            curl_setopt($this->CurlRequest,$option,$value);
        }
        return TRUE;
    }
1312605
protected function createCurlHandle()
    {
        $options = $this->getDefaultCurlOptions();

        if (isset($this->authentication)) {
            $options[CURLOPT_USERPWD] = $this->authentication;
        }

        $curl = curl_init();
        curl_setopt_array($curl, $options);

        return $curl;
    }
61509
private function execute() {
        $curlResponse = curl_exec($this->curl);

        $error = $this->getError();
        if (!empty($error)) {
            return $this->curlException($error['error'], $error['error_no']);
        }

        return $curlResponse;
    }
586821
private function buildResponse() {

        $curlOptions = $this->getBasicCurlOptions();
        $this->addRequestAuth($curlOptions);
        $this->addRequestHeaders($curlOptions);
        $this->addRequestMethod($curlOptions);

        // push options into the resource
        $curlResource = $this->getCurlResource();
        if (!curl_setopt_array($curlResource, $curlOptions)) {
            throw new RequestException('Invalid cURL options');
        }

        // create response
        $response = new Response($curlResource);
        return $response;
    }
398293
protected function _initialize() {
        $this->_ch = curl_init();
        $this->_last_info = FALSE;
        curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($this->_ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($this->_ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($this->_ch, CURLOPT_USERPWD, "{$this->_username}:{$this->_password}");

        return;
    }
746709
public function curlInit()
    {
        if ($this->offline === false) {
            $this->curl = \curl_init(); // create curl resource
            curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); // return content as a string from curl_exec
            curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); // follow redirects (compatibility for future changes in FlexiBee)
            curl_setopt($this->curl, CURLOPT_HTTPAUTH, true);       // HTTP authentication
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); // FlexiBee by default uses Self-Signed certificates
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($this->curl, CURLOPT_VERBOSE, ($this->debug === true)); // For debugging
            if (empty($this->authSessionId)) {
                curl_setopt($this->curl, CURLOPT_USERPWD,
                    $this->user.':'.$this->password); // set username and password
            }
            if (!is_null($this->timeout)) {
                curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout);
            }
        }
        return !$this->offline;
    }
17864
public function reset()
    {
        if ($this->curl !== null) {
            curl_close($this->curl); //stop curl
        }

        //reset all options
        $this->unsetOptions();

        //reset response & status code
        $this->curl = null;
        $this->response = null;
        $this->responseCode = null;

        return $this;
    }
613853
private function initHandle($curl)
    {
        // Set callbacks if not already individually set.
        if ($curl->beforeSendFunction === null) {
            $curl->beforeSend($this->beforeSendFunction);
        }
        if ($curl->successFunction === null) {
            $curl->success($this->successFunction);
        }
        if ($curl->errorFunction === null) {
            $curl->error($this->errorFunction);
        }
        if ($curl->completeFunction === null) {
            $curl->complete($this->completeFunction);
        }

        foreach ($this->options as $option => $value) {
            $curl->setOpt($option, $value);
        }
        foreach ($this->headers as $key => $value) {
            $curl->setHeader($key, $value);
        }
        $curl->setJsonDecoder($this->jsonDecoder);
        $curl->setXmlDecoder($this->xmlDecoder);
        $curl->call($curl->beforeSendFunction);
    }
63347
private static function initialize()
    {
        if (self::$initialized) return;

        self::$client = \OpenId::getClient();
        self::$version = config('openid.api-version');
        self::$initialized = TRUE;
    }