返回curl option CURLOPT_HEADERFUNCTION

@return callable
502527
private function getCurloptHeaderFunction() : callable
    {
        return function($ch, $data){
            $str = trim($data);
            if('' !== $str){
                if(strpos(strtolower($str), 'http/') === 0){
                    $status_line                                        = $str;
                    @list($http_version, $http_code, $reason_phrase)    = explode(' ', $status_line, 3);
                    $this->Response = $this->Response->withStatus((int) $http_code, (string) $reason_phrase);
                    $this->Response = $this->Response->withProtocolVersion((string) $http_version);
                }else{
                    $header_line            = $str;
                    @list($name, $value)    = explode(':', $header_line, 2);
                    $this->Response         = $this->Response->withAddedHeader(trim((string) $name), trim((string) $value));
                }
            }
            return strlen($data);
        };
    }
157832
private static function getCurl()
    {
        $args = func_get_args();
        $args = count($args) > 1 ? $args : array_shift($args);

        $uri      = $args[0];
        $options  = $args[1] ?? [];
        $callback = $args[2] ?? null;

        $ch = curl_init($uri);

        $response = static::curlExecFollow($ch, $options, $callback);
        $errno = curl_errno($ch);

        if ($errno) {
            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $error_message = curl_strerror($errno) . "\n" . curl_error($ch);

            switch ($code) {
                case '404':
                    throw new \RuntimeException('Page not found');
                case '401':
                    throw new \RuntimeException('Invalid LICENSE');
                default:
                    throw new \RuntimeException("Error while trying to download (code: $code): $uri \nMessage: $error_message");
            }
        }

        curl_close($ch);

        return $response;
    }
319903
protected function curlInit()
    {
        $curlHandle = curl_init();
        curl_setopt($curlHandle, CURLOPT_URL, $this->requestUrl);
        $this->requestUrl = $this->url;  // Reset request URL
        // Set Curl Options
        foreach ($this->curlOptions as $key => $value) {
            curl_setopt($curlHandle, $key, $value);
        }

        // Check if have header
        if (count($this->requestHeader) > 0) {
            curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->requestHeader);
            $this->requestHeader = []; // Reset request Header
        }

        // Add Cookies
        if (count($this->cookies) > 0) {
            curl_setopt($curlHandle, CURLOPT_COOKIE, implode(";", $this->cookies));
            $this->cookies = []; // Reset request Header
        }

        // Set last fetched URL
        $this->lastFetchedUrl = null;

        return $curlHandle;
    }
879616
public function read( $curlOptions = array() )
	{
		$curl		= new Net_CURL( $this->url );

		$curl->setOption( CURLOPT_SSL_VERIFYHOST, $this->verifyHost );
		$curl->setOption( CURLOPT_SSL_VERIFYPEER, $this->verifyPeer );
		$curl->setOption( CURLOPT_FOLLOWLOCATION, !ini_get( 'safe_mode' ) && !ini_get( 'open_basedir' ) );
		$curl->setOption( CURLOPT_HEADER, TRUE );
		if( self::$userAgent )
			$curl->setOption( CURLOPT_USERAGENT, self::$userAgent );
		if( $this->username )
			$curl->setOption( CURLOPT_USERPWD, $this->username.":".$this->password );
		if( $this->proxyAddress ){
			$curl->setOption( CURLOPT_HTTPPROXYTUNNEL, TRUE);
			$curl->setOption( CURLOPT_PROXY, $this->proxyAddress );
			$curl->setOption( CURLOPT_PROXYTYPE, $this->proxyType );
			if( $this->proxyAuth )
				$curl->setOption( CURLOPT_PROXYUSERPWD, $this->proxyAuth );
		}

		foreach( $curlOptions as $key => $value )
		{
			if( is_string( $key ) )
			{
				if( !( preg_match( "@^CURLOPT_@", $key ) && defined( $key ) ) )
					throw new InvalidArgumentException( 'Invalid option constant key "'.$key.'"' );
				$key	= constant( $key );
			}
			if( !is_int( $key ) )
				throw new InvalidArgumentException( 'Option must be given as integer or string' );
			$curl->setOption( $key, $value );
		}
		$result			= $curl->exec( TRUE, FALSE );
		$response		= Net_HTTP_Response_Parser::fromString( $result );

		$this->body		= $response->getBody();
		$this->headers	= $response->getHeaders();
		$this->info		= $curl->getInfo();
		$code			= $curl->getInfo( Net_CURL::INFO_HTTP_CODE );
		$error			= $curl->getInfo( Net_CURL::INFO_ERROR );
		$errno			= $curl->getInfo( Net_CURL::INFO_ERRNO );
		if( $errno )
			throw new Exception_IO( 'HTTP request failed: '.$error, $errno, $this->url );
		if( !in_array( $code, array( '200', '301', '303', '304', '307' ) ) )
			throw new Exception_IO( 'HTTP request failed', $code, $this->url );
		return $this->body;
	}
891432
public function getOptions()
    {
        foreach ($this->defaultOpts() as $k => $v) {
            if (!isset($this->_options[$k])) {
                $this->_options[$k] = $v;
            }
        }
        // !important see headerCallback() function
        $this->_options[CURLOPT_HEADER] = false;
        return $this->_options;
    }
794229
public function headerfunction($curl, string $line):int{
		$str    = \trim($line);
		$header = \explode(':', $str, 2);

		if(\count($header) === 2){
			$this->response = $this->response
				->withAddedHeader(\trim($header[0]), \trim($header[1]));
		}
		elseif(\substr(\strtoupper($str), 0, 5) === 'HTTP/'){
			$status = \explode(' ', $str, 3);
			$reason = \count($status) > 2 ? \trim($status[2]) : '';

			$this->response = $this->response
				->withStatus((int)$status[1], $reason)
				->withProtocolVersion(\substr($status[0], 5));
		}

		return \strlen($line);
	}
840987
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()
            );
        }

        // Set json
        if (($json = $this->getJson()) != null) {
            $options['json'] = $json;
            $this->setAccept('application/json');
        }

        if (($formParams = $this->getFormParams()) != null) {
            $options['body'] = $formParams;
            $this->setContentType('application/x-www-form-urlencoded');
        }

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

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

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

        $response = $this->getHttpClient()->send($request);

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

        $this->setData($response->json());
    }
1301391
private function httpClient()
    {
        if (!self::$httpClient) {
            self::$httpClient = HttpClient\CurlClient::instance();
        }
        return self::$httpClient;
    }
482698
private function chooseHttpClient()
    {
        if (null !== $this->httpClient) {
            return $this->httpClient;
        }

        $this->consoleLogger
            ->debug('Choosing HttpClient implementation.');

        if (\function_exists('curl_exec')) {
            $this->httpClient = $this->curlHttpClient;

            $this->consoleLogger
                ->debug('cURL available, use <info>CurlHttpClient</info>.');

            return $this->httpClient;
        }

        if ('1' === \ini_get('allow_url_fopen')) {
            $this->httpClient = $this->streamHttpClient;

            $this->consoleLogger
                ->debug("'allow_url_fopen' enabled, use <info>StreamHttpClient</info>");

            return $this->httpClient;
        }

        $this->consoleLogger
            ->debug('<error>Choosing HttpClient implementation failed.</error>');

        throw new HttpClientException(
            "Unable to choose HttpClient. Enable cURL extension (preffered) or turn on 'allow_url_fopen' in php.ini."
        );
    }
789691
protected function get_curl_obj()
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verify_peer);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->curl_ssl_verify_host);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout);

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

        if ($this->cookies != '') {
            curl_setopt($ch, CURLOPT_COOKIESESSION, true);
            curl_setopt($ch, CURLOPT_COOKIE, $this->cookies);
        }

        return $ch;
    }
534125
function http($url, $method, $postfields=null, $headers=array())
    {
        $this->http_info = array();
        $ci = curl_init();
        /* Curl settings */
        curl_setopt($ci, CURLOPT_USERAGENT, self::USER_AGENT);
        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
        curl_setopt($ci, CURLOPT_TIMEOUT, self::REQUEST_TIMEOUT);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);

        // Set request headers if any
        if (is_array($headers) && !empty($headers)){
            $this->http_request_headers = $headers;
            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
        }

        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, self::SSL_VERIFY_PEER);
        curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
        curl_setopt($ci, CURLOPT_HEADER, false);

        // Make sure the post fields are string
        if (is_array($postfields) && !empty($postfields)) {
            $postfields = http_build_query($postfields);
        }

        switch ($method) {
            case 'POST':
                curl_setopt($ci, CURLOPT_POST, true);
                if (!empty($postfields)) {
                    $this->http_post = $postfields;
                    curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                }
                break;
            case 'DELETE':
                curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
                if (!empty($postfields)) {
                    $url = "{$url}?{$postfields}";
                }
        }

        curl_setopt($ci, CURLOPT_URL, $url);
        $response = curl_exec($ci);
        $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
        $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
        $this->http_url = $url;
        curl_close($ci);

        return $response;
    }
1191031
private function curl( $url, $headerParams, $post = true ) {

		$authHeader	= $this->generateAuthHeader( $headerParams );
		$authHeader	= [ $authHeader, 'Expect:' ];

		$ch = curl_init();

		curl_setopt( $ch, CURLOPT_HTTPHEADER, $authHeader );
		curl_setopt( $ch, CURLOPT_HEADER, false );
		curl_setopt( $ch, CURLOPT_URL, $url );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

		if( $post ) {

			curl_setopt( $ch, CURLOPT_POST, true );
		}

		curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );

		$data = curl_exec( $ch );

		curl_close( $ch );

		return $data;
	}
1281279
public function setHeader($header)
    {
        $headers = [];

        if (is_array($header)) {
            foreach ($header as $key => $value) {
                $headers[] = $key . ': ' . $value;
            }
        } else {
            $headers[] = $header;
        }

        $this->setOpt(CURLOPT_HTTPHEADER, $headers);

        return $this;
    }
673795
private function configureCurl()
    {
        foreach($this->getCurlOptions() as $option => $value){
            curl_setopt($this->CurlRequest,$option,$value);
        }
        return TRUE;
    }
616899
protected function setPostCurlopts()
    {
        $curlopts = [
            CURLOPT_HTTPHEADER => $this->headers,
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => $this->postFields,
            CURLOPT_HEADER => 0,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_VERBOSE => false,
            CURLOPT_RETURNTRANSFER => true
        ];

        return $curlopts;
    }
719905
protected function setOptions() {
        $this->resource->setOption(CURLOPT_URL, $this->createUrl());
        $this->resource->setOption(CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
        $this->resource->setOption(CURLOPT_RETURNTRANSFER, true);
        $this->resource->setOption(CURLOPT_HEADER, true);

        $this->resource->setOption(
            CURLOPT_FOLLOWLOCATION,
            $this->options->get(HttpClientOptions::FOLLOW_REDIRECT, false)
        );

        if ($this->options->get(HttpClientOptions::VERIFY_SSL, true)) {
            $this->resource->setOption(CURLOPT_SSL_VERIFYPEER, true);
            $this->resource->setOption(CURLOPT_SSL_VERIFYHOST, 2);
        } else {
            $this->resource->setOption(CURLOPT_SSL_VERIFYPEER, false);
            $this->resource->setOption(CURLOPT_SSL_VERIFYHOST, false);
        }

        foreach ($this->options->toArray() as $option => $value) {
            if (str_starts_with($option, 'CURLOPT_') && defined($option)) {
                $this->resource->setOption(constant($option), $value);
            }
        }
    }
1180967
protected function addHeaders()
    {
        if (empty($this->headers)) {
            return $this;
        }

        $this->options[CURLOPT_HTTPHEADER] = $this->headers;
        return $this;
    }