public function sendRequest()

in src/Client/Curl.php [67:111]


    public function sendRequest(RequestInterface $request): ResponseInterface
    { 
        curl_reset($this->getCurl());

        $headers = [];
        foreach ($request->getHeaders() as $name => $values) {
            foreach ($values as $value) {
                $headers[] = sprintf("%s: %s", $name, $value);
            }
        }
        $curlOptions = [
            CURLOPT_HTTP_VERSION   => $this->getCurlHttpVersion($request->getProtocolVersion()),
            CURLOPT_CUSTOMREQUEST  => $request->getMethod(),
            CURLOPT_CONNECTTIMEOUT => 0,
            CURLOPT_URL            => (string) $request->getUri(),
            CURLOPT_NOBODY         => $request->getMethod() === 'HEAD',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER         => true,
            CURLOPT_HTTPHEADER     => $headers
        ];
        
        if (!in_array($request->getMethod(), self::BODYLESS_HTTP_METHODS, true)) {
            $curlOptions[CURLOPT_POSTFIELDS] = (string) $request->getBody();
        }

        curl_setopt_array($this->getCurl(), array_replace($curlOptions, $this->options));
        $response = curl_exec($this->getCurl());
        
        if ($response !== false && curl_errno($this->getCurl()) === 0) {
            $parse = $this->parseResponse((string) $response);
            return new Response(
                $parse['status-code'], 
                $parse['headers'], 
                $parse['body'],
                $parse['http-version'],
                $parse['reason-phrase']
            );
        }

        throw new CurlException(sprintf(
            "Error sending with cURL (%d): %s",
            curl_errno($this->getCurl()),
            curl_error($this->getCurl())
        ));
    }