private function setOptionsFromRequest($curl, RequestInterface $request): void
    {
        $options = [
            CURLOPT_CUSTOMREQUEST => $request->getMethod(),
            CURLOPT_URL => $request->getUri()->__toString(),
            CURLOPT_HTTPHEADER => HeaderConverter::toBuzzHeaders($request->getHeaders()),
        ];

        if (0 !== $version = $this->getProtocolVersion($request)) {
            $options[CURLOPT_HTTP_VERSION] = $version;
        }

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

        switch (strtoupper($request->getMethod())) {
            case 'HEAD':
                $options[CURLOPT_NOBODY] = true;

                break;

            case 'GET':
                $options[CURLOPT_HTTPGET] = true;

                break;

            case 'POST':
            case 'PUT':
            case 'DELETE':
            case 'PATCH':
            case 'OPTIONS':
                $body = $request->getBody();
                $bodySize = $body->getSize();
                if (0 !== $bodySize) {
                    if ($body->isSeekable()) {
                        $body->rewind();
                    }

                    // Message has non empty body.
                    if (null === $bodySize || $bodySize > 1024 * 1024) {
                        // Avoid full loading large or unknown size body into memory
                        $options[CURLOPT_UPLOAD] = true;
                        if (null !== $bodySize) {
                            $options[CURLOPT_INFILESIZE] = $bodySize;
                        }
                        $options[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
                            return $body->read($length);
                        };
                    } else {
                        // Small body can be loaded into memory
                        $options[CURLOPT_POSTFIELDS] = (string) $body;
                    }
                }
        }

        curl_setopt_array($curl, $options);
    }
private function setOptionsFromRequest($curl, RequestInterface $request): void
    {
        $options = [
            CURLOPT_CUSTOMREQUEST => $request->getMethod(),
            CURLOPT_URL => $request->getUri()->__toString(),
            CURLOPT_HTTPHEADER => HeaderConverter::toBuzzHeaders($request->getHeaders()),
        ];

        if (0 !== $version = $this->getProtocolVersion($request)) {
            $options[CURLOPT_HTTP_VERSION] = $version;
        }

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

        switch (strtoupper($request->getMethod())) {
            case 'HEAD':
                $options[CURLOPT_NOBODY] = true;

                break;

            case 'GET':
                $options[CURLOPT_HTTPGET] = true;

                break;

            case 'POST':
            case 'PUT':
            case 'DELETE':
            case 'PATCH':
            case 'OPTIONS':
                $body = $request->getBody();
                $bodySize = $body->getSize();
                if (0 !== $bodySize) {
                    if ($body->isSeekable()) {
                        $body->rewind();
                    }

                    // Message has non empty body.
                    if (null === $bodySize || $bodySize > 1024 * 1024) {
                        // Avoid full loading large or unknown size body into memory
                        $options[CURLOPT_UPLOAD] = true;
                        if (null !== $bodySize) {
                            $options[CURLOPT_INFILESIZE] = $bodySize;
                        }
                        $options[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
                            return $body->read($length);
                        };
                    } else {
                        // Small body can be loaded into memory
                        $options[CURLOPT_POSTFIELDS] = (string) $body;
                    }
                }
        }

        curl_setopt_array($curl, $options);
    }
private function setOptionsFromRequest ( $ curl , RequestInterface $ request ) : void { $ options = [ CURLOPT_CUSTOMREQUEST => $ request -> getMethod ( ) , CURLOPT_URL => $ request -> getUri ( ) -> __toString ( ) , CURLOPT_HTTPHEADER => HeaderConverter :: toBuzzHeaders ( $ request -> getHeaders ( ) ) , ] ; if ( 0 !== $ version = $ this -> getProtocolVersion ( $ request ) ) { $ options [ CURLOPT_HTTP_VERSION ] = $ version ; } if ( $ request -> getUri ( ) -> getUserInfo ( ) ) { $ options [ CURLOPT_USERPWD ] = $ request -> getUri ( ) -> getUserInfo ( ) ; } switch ( strtoupper ( $ request -> getMethod ( ) ) ) { case 'HEAD' : $ options [ CURLOPT_NOBODY ] = true ; break ; case 'GET' : $ options [ CURLOPT_HTTPGET ] = true ; break ; case 'POST' : case 'PUT' : case 'DELETE' : case 'PATCH' : case 'OPTIONS' : $ body = $ request -> getBody ( ) ; $ bodySize = $ body -> getSize ( ) ; if ( 0 !== $ bodySize ) { if ( $ body -> isSeekable ( ) ) { $ body -> rewind ( ) ; } // Message has non empty body. if ( null === $ bodySize || $ bodySize > 1024 * 1024 ) { // Avoid full loading large or unknown size body into memory $ options [ CURLOPT_UPLOAD ] = true ; if ( null !== $ bodySize ) { $ options [ CURLOPT_INFILESIZE ] = $ bodySize ; } $ options [ CURLOPT_READFUNCTION ] = function ( $ ch , $ fd , $ length ) use ( $ body ) { return $ body -> read ( $ length ) ; } ; } else { // Small body can be loaded into memory $ options [ CURLOPT_POSTFIELDS ] = ( string ) $ body ; } } } curl_setopt_array ( $ curl , $ options ) ; }
Sets options on a cURL resource based on a request.

@param resource         $curl    A cURL resource
@param RequestInterface $request A request object
Sets options on a cURL resource based on a request .