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;
    }