@param RequestInterface                   $request
@param array                              $options
@param ResponseInterface|PromiseInterface $response

@return ResponseInterface|PromiseInterface
167048
public function processResponse(RequestInterface $request, array $options, ResponseInterface $response)
    {
        $response = $response
            ->withHeader('X-Blackfire-Profile-Uuid', $request->getHeader('X-Blackfire-Profile-Uuid'))
            ->withHeader('X-Blackfire-Profile-Url', $request->getHeader('X-Blackfire-Profile'))
        ;

        if (!$response->hasHeader('X-Blackfire-Response')) {
            if (null !== $this->logger) {
                $this->logger->warning('Profile request failed.', array(
                    'profile-uuid' => $request->getHeader('X-Blackfire-Profile-Uuid'),
                    'profile-url' => $request->getHeader('X-Blackfire-Profile-Url'),
                ));
            }

            return $response;
        }

        parse_str($response->getHeader('X-Blackfire-Response')[0], $values);

        if (!isset($values['continue']) || 'true' !== $values['continue']) {
            if (null !== $this->logger) {
                $this->logger->debug('Profile request succeeded.', array(
                    'profile-uuid' => $request->getHeader('X-Blackfire-Profile-Uuid'),
                    'profile-url' => $request->getHeader('X-Blackfire-Profile'),
                ));
            }

            return $response;
        }

        Psr7\rewind_body($request);

        /* @var PromiseInterface|ResponseInterface $promise */
        return $this($request, $options);
    }
1197975
public function requestAsync($method, $uri = '', array $options = []): PromiseInterface
    {
        // Ensure the “X-Request-Id” header gets regenerated for every call.
        $options['headers']['X-Request-Id'] = $this->generateV4GUID();

        return parent::requestAsync($method, $uri, $options);
    }
451091
public function doRequest($request, $options = null)
    {
        $request = array_merge($request, array(
            'Version'        => $this->_config->version,
            'ProcessorId'    => $this->_config->processorId,
            'MerchantId'     => $this->_config->merchantId,
            'TransactionPwd' => $this->_config->transactionPwd,
        ));

        $xml = new DOMDocument('1.0', 'utf-8');
        $envelope = $xml->createElement('CardinalMPI');
        foreach ($request as $k => $v) {
            $envelope->appendChild($xml->createElement($k, $v));
        }
        $xml->appendChild($envelope);

        $url = $this->_config->serviceUri();
        $xmlData = $xml->saveXML();
        $data = 'cmpi_msg=' . urlencode($xmlData);
        $header = array(
            'Content-type: application/x-www-form-urlencoded;charset="utf-8"',
            'Accept: text/xml',
            'Content-length: '.strlen($data),
        );
        // error_log($xmlData);

        return $this->submitRequest($url, $header, $data);
    }
1153378
public function applyResponse(HttpRequestInterface $request, HttpResponseInterface $response, array $options)
    {
        if ($response instanceof ResponseInterface &&
            isset($options['rpc_error']) &&
            true === $options['rpc_error'] &&
            null !== $response->getRpcErrorCode()
        ) {
            throw RequestException::create($request, $response);
        }

        return $response;
    }
741203
private function applyOptions(RequestInterface $request, array &$options)
    {
        $modify = [
            'set_headers' => [],
        ];

        if (isset($options['headers'])) {
            $modify['set_headers'] = $options['headers'];
            unset($options['headers']);
        }

        if (isset($options['form_params'])) {
            if (isset($options['multipart'])) {
                throw new \InvalidArgumentException('You cannot use '
                    . 'form_params and multipart at the same time. Use the '
                    . 'form_params option if you want to send application/'
                    . 'x-www-form-urlencoded requests, and the multipart '
                    . 'option to send multipart/form-data requests.');
            }
            $options['body'] = http_build_query($options['form_params'], '', '&');
            unset($options['form_params']);
            // Ensure that we don't have the header in different case and set the new value.
            $options['_conditional'] = Psr7\_caseless_remove(['Content-Type'], $options['_conditional']);
            $options['_conditional']['Content-Type'] = 'application/x-www-form-urlencoded';
        }

        if (isset($options['multipart'])) {
            $options['body'] = new Psr7\MultipartStream($options['multipart']);
            unset($options['multipart']);
        }

        if (isset($options['json'])) {
            $options['body'] = \GuzzleHttp\json_encode($options['json']);
            unset($options['json']);
            // Ensure that we don't have the header in different case and set the new value.
            $options['_conditional'] = Psr7\_caseless_remove(['Content-Type'], $options['_conditional']);
            $options['_conditional']['Content-Type'] = 'application/json';
        }

        if (!empty($options['decode_content'])
            && $options['decode_content'] !== true
        ) {
            // Ensure that we don't have the header in different case and set the new value.
            $options['_conditional'] = Psr7\_caseless_remove(['Accept-Encoding'], $options['_conditional']);
            $modify['set_headers']['Accept-Encoding'] = $options['decode_content'];
        }

        if (isset($options['body'])) {
            if (is_array($options['body'])) {
                $this->invalidBody();
            }
            $modify['body'] = Psr7\stream_for($options['body']);
            unset($options['body']);
        }

        if (!empty($options['auth']) && is_array($options['auth'])) {
            $value = $options['auth'];
            $type = isset($value[2]) ? strtolower($value[2]) : 'basic';
            switch ($type) {
                case 'basic':
                    // Ensure that we don't have the header in different case and set the new value.
                    $modify['set_headers'] = Psr7\_caseless_remove(['Authorization'], $modify['set_headers']);
                    $modify['set_headers']['Authorization'] = 'Basic '
                        . base64_encode("$value[0]:$value[1]");
                    break;
                case 'digest':
                    // @todo: Do not rely on curl
                    $options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST;
                    $options['curl'][CURLOPT_USERPWD] = "$value[0]:$value[1]";
                    break;
                case 'ntlm':
                    $options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_NTLM;
                    $options['curl'][CURLOPT_USERPWD] = "$value[0]:$value[1]";
                    break;
            }
        }

        if (isset($options['query'])) {
            $value = $options['query'];
            if (is_array($value)) {
                $value = http_build_query($value, null, '&', PHP_QUERY_RFC3986);
            }
            if (!is_string($value)) {
                throw new \InvalidArgumentException('query must be a string or array');
            }
            $modify['query'] = $value;
            unset($options['query']);
        }

        // Ensure that sink is not an invalid value.
        if (isset($options['sink'])) {
            // TODO: Add more sink validation?
            if (is_bool($options['sink'])) {
                throw new \InvalidArgumentException('sink must not be a boolean');
            }
        }

        $request = Psr7\modify_request($request, $modify);
        if ($request->getBody() instanceof Psr7\MultipartStream) {
            // Use a multipart/form-data POST if a Content-Type is not set.
            // Ensure that we don't have the header in different case and set the new value.
            $options['_conditional'] = Psr7\_caseless_remove(['Content-Type'], $options['_conditional']);
            $options['_conditional']['Content-Type'] = 'multipart/form-data; boundary='
                . $request->getBody()->getBoundary();
        }

        // Merge in conditional headers if they are not present.
        if (isset($options['_conditional'])) {
            // Build up the changes so it's in a single clone of the message.
            $modify = [];
            foreach ($options['_conditional'] as $k => $v) {
                if (!$request->hasHeader($k)) {
                    $modify['set_headers'][$k] = $v;
                }
            }
            $request = Psr7\modify_request($request, $modify);
            // Don't pass this internal value along to middleware/handlers.
            unset($options['_conditional']);
        }

        return $request;
    }
549789
public function sendRequest($request, $options = [])
    {
        $client = $this->client;
        $response = $client->send($request, $options);

        return $response;
    }
423324
protected function request($options = [])
    {
        try {
            $params = array_filter($this->params);
            $response = $this->getClient()
                ->get($this->getUrl(), ['query' => $params], $options);

            return trim($this->format) === 'json'
                ? json_decode($response->getBody(), true)
                : simplexml_load_string($response->getBody());
        } catch (RequestException $e) {
            return null;
        }
    }
453531
protected function prepare($curl, RequestInterface $request, array $options): ResponseInterface
    {
        if (\defined('CURLOPT_PROTOCOLS')) {
            \curl_setopt($curl, \CURLOPT_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
            \curl_setopt($curl, \CURLOPT_REDIR_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
        }

        \curl_setopt($curl, \CURLOPT_HEADER, false);
        \curl_setopt($curl, \CURLOPT_RETURNTRANSFER, false);
        \curl_setopt($curl, \CURLOPT_FAILONERROR, false);

        $this->setOptionsFromParameter($curl, $options);
        $this->setOptionsFromRequest($curl, $request);

        $response = Factory::response();
        \curl_setopt($curl, \CURLOPT_HEADERFUNCTION, function ($ch, $data) use ($response) {
            $str = \trim($data);
            if ('' !== $str) {
                if (0 === \stripos($str, 'http/')) {
                    $this->setStatus($response, $str);
                } else {
                    $this->addHeader($response, $str);
                }
            }

            return \strlen($data);
        });

        \curl_setopt($curl, \CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($response) {
            return $response->getBody()->write($data);
        });

        // apply additional options
        if ($options['curl'] !== []) {
            \curl_setopt_array($curl, $options['curl']);
        }

        return $response;
    }
1342406
public function send($method, $uri, array $options = [])
    {
        $this->calls[] = array('send', $method, $uri, $options);

        return new Response();
    }
1151797
protected function respond($success, $request, $response, $options)
    {
        $success = isset($response['ACK']) && in_array($response['ACK'], ['Success', 'SuccessWithWarning']);

        if (array_key_exists('INVALID', $response) || array_key_exists('VERIFIED', $response)) {
            $response = array_merge($response, $request);
        }

        $response['isRedirect'] = Arr::get($options, 'isRedirect', false);

        return $this->mapResponse($success, $response);
    }
468031
protected function doRetry(RequestInterface $request, array $options, ResponseInterface $response = null)
    {
        // Increment the retry count
        ++$options['retry_count'];

        // Determine the delay timeout
        $delayTimeout = $this->determineDelayTimeout($options, $response);

        // Callback?
        if ($options['on_retry_callback']) {
            \call_user_func(
                $options['on_retry_callback'],
                (int) $options['retry_count'],
                (float) $delayTimeout,
                $request,
                $options,
                $response
            );
        }

        // Delay!
        usleep($delayTimeout * 1000000);

        // Return
        return $this($request, $options);
    }
1083601
protected function handleRequest($method, $resource, $options)
    {
        $response = null;
        try
        {
            $response = $this->handleResponse($this->getHttpClient()->request($method, $resource, $options));
        }
        catch (RequestException $e)
        {
            $this->handleException($e);
        }

        return $response;
    }
1186678
public function send(RequestInterface $request, array $options = [])
    {
        $options = array_merge($options, ['http_errors' => false]);

        $psr7Response = $this->guzzle->send($request, $options);

        if ($psr7Response->getStatusCode() === 400) {
            $responseArray = \GuzzleHttp\json_decode($psr7Response->getBody(), true);
            throw new AffilinetProductWebserviceException($responseArray['ErrorMessages'][0]['Value']);
        }

        return $psr7Response;
    }
519615
public static function send(RequestInterface $request, ClientInterface $client, array $options = [])
    {
        $response = null;
        try {
            $response = $client->send($request, $options);
            $body = $response->getBody()->getContents();
            $data = [];
            if ($body) {
                $response->getBody()->seek(0);
                $body = $response->getBody()->getContents();
                $data = \GuzzleHttp\json_decode($body, true);
            }

            return (array) $data;
        } catch (BadResponseException $e) {
            throw ApiResponseException::create($e->getRequest(), $e->getResponse());
        } catch (\InvalidArgumentException $e) {
            throw ApiResponseException::create($request, $response);
        }
    }
276241
public function responseToResultTransformer(ResponseInterface $response, RequestInterface $request)
    {
        $data = json_decode($response->getBody(), true);

        return new Result($data);
    }
1225224
public function dispatch(RequestInterface $request, ResponseInterface $response)
    {
        $this->middleware = array_reverse($this->middleware);

        $resolved = $this->resolve(0);

        return yield $resolved($request, $response);
    }
1092411
public function post(
        ResponseInterface $response,
        string $transactionId,
        array $options = []
    ): CancellablePromiseInterface {
        if ($response->getBody() instanceof ReadableStreamInterface) {
            return resolve($response);
        }

        if (!isset($options[self::class]) &&
        strpos($response->getHeaderLine('Content-Type'), 'text/xml') !== 0) {
            return resolve($response);
        }

        if (isset($options[self::class][Options::CONTENT_TYPE]) &&
        $response->getHeaderLine('Content-Type') !== $options[self::class][Options::CONTENT_TYPE]) {
            return resolve($response);
        }

        $body = (string)$response->getBody();
        if ($body === '') {
            $stream = new BufferStream(0);
            $stream->write($body);

            return resolve($response->withBody($stream));
        }

        return $this->xmlDecodeService->decode($body)->then(function (array $xml) use ($response) {
            return resolve($response->withBody(new XmlStream($xml)));
        });
    }