private function prepareRequestOptions(
        RequestInterface $request,
        ResponseBuilder $responseBuilder
    ): array {
        $curlOptions = $this->curlOptions;

        try {
            $curlOptions[CURLOPT_HTTP_VERSION]
                = $this->getProtocolVersion($request->getProtocolVersion());
        } catch (\UnexpectedValueException $e) {
            throw new Exception\RequestException($e->getMessage(), $request);
        }
        $curlOptions[CURLOPT_URL] = (string)$request->getUri();

        $curlOptions = $this->addRequestBodyOptions($request, $curlOptions);

        $curlOptions[CURLOPT_HTTPHEADER] = $this->createHeaders($request, $curlOptions);

        if ($request->getUri()->getUserInfo()) {
            $curlOptions[CURLOPT_USERPWD] = $request->getUri()->getUserInfo();
        }

        $curlOptions[CURLOPT_HEADERFUNCTION] = function ($ch, $data) use ($responseBuilder) {
            $str = trim($data);
            if ('' !== $str) {
                if (stripos($str, 'http/') === 0) {
                    $responseBuilder->setStatus($str)->getResponse();
                } else {
                    $responseBuilder->addHeader($str);
                }
            }

            return strlen($data);
        };

        $curlOptions[CURLOPT_WRITEFUNCTION] = function ($ch, $data) use ($responseBuilder) {
            return $responseBuilder->getResponse()->getBody()->write($data);
        };

        return $curlOptions;
    }
private function prepareRequestOptions(
        RequestInterface $request,
        ResponseBuilder $responseBuilder
    ): array {
        $curlOptions = $this->curlOptions;

        try {
            $curlOptions[CURLOPT_HTTP_VERSION]
                = $this->getProtocolVersion($request->getProtocolVersion());
        } catch (\UnexpectedValueException $e) {
            throw new Exception\RequestException($e->getMessage(), $request);
        }
        $curlOptions[CURLOPT_URL] = (string)$request->getUri();

        $curlOptions = $this->addRequestBodyOptions($request, $curlOptions);

        $curlOptions[CURLOPT_HTTPHEADER] = $this->createHeaders($request, $curlOptions);

        if ($request->getUri()->getUserInfo()) {
            $curlOptions[CURLOPT_USERPWD] = $request->getUri()->getUserInfo();
        }

        $curlOptions[CURLOPT_HEADERFUNCTION] = function ($ch, $data) use ($responseBuilder) {
            $str = trim($data);
            if ('' !== $str) {
                if (stripos($str, 'http/') === 0) {
                    $responseBuilder->setStatus($str)->getResponse();
                } else {
                    $responseBuilder->addHeader($str);
                }
            }

            return strlen($data);
        };

        $curlOptions[CURLOPT_WRITEFUNCTION] = function ($ch, $data) use ($responseBuilder) {
            return $responseBuilder->getResponse()->getBody()->write($data);
        };

        return $curlOptions;
    }
private function prepareRequestOptions ( RequestInterface $ request , ResponseBuilder $ responseBuilder ) : array { $ curlOptions = $ this -> curlOptions ; try { $ curlOptions [ CURLOPT_HTTP_VERSION ] = $ this -> getProtocolVersion ( $ request -> getProtocolVersion ( ) ) ; } catch ( \ UnexpectedValueException $ e ) { throw new Exception \ RequestException ( $ e -> getMessage ( ) , $ request ) ; } $ curlOptions [ CURLOPT_URL ] = ( string ) $ request -> getUri ( ) ; $ curlOptions = $ this -> addRequestBodyOptions ( $ request , $ curlOptions ) ; $ curlOptions [ CURLOPT_HTTPHEADER ] = $ this -> createHeaders ( $ request , $ curlOptions ) ; if ( $ request -> getUri ( ) -> getUserInfo ( ) ) { $ curlOptions [ CURLOPT_USERPWD ] = $ request -> getUri ( ) -> getUserInfo ( ) ; } $ curlOptions [ CURLOPT_HEADERFUNCTION ] = function ( $ ch , $ data ) use ( $ responseBuilder ) { $ str = trim ( $ data ) ; if ( '' !== $ str ) { if ( stripos ( $ str , 'http/' ) === 0 ) { $ responseBuilder -> setStatus ( $ str ) -> getResponse ( ) ; } else { $ responseBuilder -> addHeader ( $ str ) ; } } return strlen ( $ data ) ; } ; $ curlOptions [ CURLOPT_WRITEFUNCTION ] = function ( $ ch , $ data ) use ( $ responseBuilder ) { return $ responseBuilder -> getResponse ( ) -> getBody ( ) -> write ( $ data ) ; } ; return $ curlOptions ; }
Update cURL options for given request and hook in the response builder.

@param RequestInterface $request         Request on which to create options.
@param ResponseBuilder  $responseBuilder Builder to use for building response.

@return array cURL options based on request.

@throws \InvalidArgumentException  For invalid header names or values.
@throws \RuntimeException          If can not read body.
@throws Exception\RequestException On invalid request.
Update cURL options for given request and hook in the response builder .