@param ServiceResponseInterface $response

@return array|mixed|string
336144
public static function sendScriptResponse(ServiceResponseInterface $response)
    {
        $content = $response->getContent();
        $contentType = $response->getContentType();
        $format = $response->getDataFormat();
        $headers = $response->getHeaders();

        $status = $response->getStatusCode();
        //  In case the status code is not a valid HTTP Status code
        if (!in_array($status, HttpStatusCodes::getDefinedConstants())) {
            //  Do necessary translation here. Default is Internal server error.
            $status = HttpStatusCodeInterface::HTTP_INTERNAL_SERVER_ERROR;
        }

        if ($content instanceof \Exception) {
            $status =
                ($content instanceof RestException) ? $content->getStatusCode()
                    : ServiceResponseInterface::HTTP_INTERNAL_SERVER_ERROR;
            $content = ['error' => self::exceptionToArray($content)];
            $format = DataFormats::PHP_ARRAY;
        }

        return [
            'status_code'  => $status,
            'content'      => $content,
            'content_type' => $contentType,
            'format'       => $format,
            'headers'      => $headers
        ];
    }
290646
public function getHeadersAsString(ResponseInterface $response)
    {
        $headers = $response->getHeaders();
        $rawHeaders = [];
        foreach ($headers as $name => $values) {
            $rawHeaders[] = $name . ": " . implode(", ", $values);
        }

        return implode("\r\n", $rawHeaders);
    }
320679
private function convertToZfResponse(ResponseInterface $response)
    {
        $zfResponse = new HttpResponse();

        $zfResponse->setStatusCode($response->getStatusCode());
        $zfResponse->setReasonPhrase($response->getReasonPhrase());
        $zfResponse->setContent((string) $response->getBody());

        foreach ($response->getHeaders() as $name => $values) {
            $zfResponse->getHeaders()->addHeaderLine($name, implode(", ", $values));
        }

        return $zfResponse;
    }
631164
private function decodeResponse( ResponseInterface $response ) {
		$resultArray = json_decode( $response->getBody(), true );

		$this->logWarnings( $resultArray );
		$this->throwUsageExceptions( $resultArray );

		return $resultArray;
	}
871800
protected function _unserializeResponseBody(ResponseInterface $response) {

		$body = (string) $response->getBody();
		$contentType = $response->getHeaderLine('Content-type');

		try {
			if(false !== stripos($contentType, $this->dataType)
				&& isset($this->unserializers[$this->dataType])) {
				/** @var UnserializerInterface $unserializer */
				$unserializer = \Yii::createObject($this->unserializers[$this->dataType]);
				if($unserializer instanceof UnserializerInterface) {
					return $unserializer->unserialize($body, false);
				}
			}

			return $body;

		} catch(InvalidParamException $e) {

			return $body;
		}
	}
59321
private function decodeOnEncodingHeader($headerName, ResponseInterface $response)
    {
        if ($response->hasHeader($headerName)) {
            $encodings = $response->getHeader($headerName);
            $newEncodings = [];

            while ($encoding = array_pop($encodings)) {
                $stream = $this->decorateStream($encoding, $response->getBody());

                if (false === $stream) {
                    array_unshift($newEncodings, $encoding);

                    continue;
                }

                $response = $response->withBody($stream);
            }

            $response = $response->withHeader($headerName, $newEncodings);
        }

        return $response;
    }
271999
public function response($response)
    {
        if (!($response instanceof ResponseInterface)) {
            if (is_array($response) || $response instanceof \stdClass || $response instanceof \JsonSerializable) {
                $response = Response::make(json_encode($response));
                $response = $response->withHeader('Content-Type', 'application/json');
            } elseif (is_object($response) && method_exists($response, 'render')) {
                $response = Response::make($realResponse->render());
            } elseif (is_string($response) || is_numeric($response) || is_bool($response)) {
                $response = Response::make($response);
            } else {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid response "%s"; must be an string or object has render method',
                    gettype($response)
                ));
            }
        }
        return $response;
    }
450257
public static function getResponseBodySummary(ResponseInterface $response)
    {
        if (method_exists(RequestException::class, 'getResponseBodySummary')) {
            return RequestException::getResponseBodySummary($response);
        }

        $body = \GuzzleHttp\Psr7\copy_to_string($response->getBody());

        if (\strlen($body) > 120) {
            return substr($body, 0, 120).' (truncated...)';
        }

        return $body;
    }
853772
public function handleResponse($response) {

        // No filter has been applied to this request.
        // Standard request, instantiate a single object.
        if(empty($this->filter)) {
            return $this->instantiateEntity($response);
        }

        // Filter applied.
        // Instantiate an object for each result returned.
        else {
            return array_map(function ($object) {
                return $this->instantiateEntity($object);
            }, $response->data);
        }

    }
254860
public function parseResponse($response)
    {
        $array = [];

        $exploded = explode('&', $response);

        foreach ($exploded as $explode) {
            $line = explode('=', $explode);

            if (isset($line[1])) {
                $array[$line[0]] = urldecode($line[1]);
            } else {
                $array[] = $explode;
            }
        }

        return $array;
    }
554984
private function parseResponse(string $response)
    {
        if (0 === preg_match_all('~--uuid:[a-zA-Z0-9-]+~', $response, $matches, PREG_OFFSET_CAPTURE)) {
            return [[
                'headers' => [
                    'Content-Type'              => 'application/json;charset=UTF-8',
                    'Content-Transfer-Encoding' => 'binary',
                    'Content-ID'                => '<jsonInfos>',
                ],
                'body'    => $response,
            ]];
        }

        $uuids = $matches[0];

        $parts = [];

        for ($i = 0; $i < count($uuids) - 1; $i++) {
            $start = $uuids[$i][1] + strlen($uuids[$i][0]) + 2;
            $parts[] = substr($response, $start, $uuids[$i + 1][1] - $start);
        }

        $responses = [];

        foreach ($parts as $part) {
            list($header, $body) = explode("\r\n\r\n", $part);

            $headers = [];
            foreach (explode("\r\n", $header) as $line) {
                list($key, $value) = explode(':', $line);
                $headers[trim($key)] = trim($value);
            }

            $responses[] = [
                'headers' => $headers,
                'body'    => $body,
            ];
        }

        return $responses;
    }
1195612
protected function prepareResponse($response)
    {
        $header_size = curl_getinfo($this->request, CURLINFO_HEADER_SIZE);
        $headers = substr($response, 0, $header_size);
        $body = substr($response, $header_size);

        return [$headers, $body];
    }
1256160
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode'] && !empty($jsonData['result'])) {
            $messages = [];
            foreach ($jsonData['result'] as $messageData) {
                $messages[] = static::makeResponseMessage($messageData['poll_type'], $messageData);
            }

            return $messages;
        } elseif (103 == $jsonData['retcode']) {
            throw new Code103ResponseException($response);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
1170659
protected function parseResponse(ResponseInterface $response)
    {
        $content = (string)$response->getBody();
        $type = $this->getContentType($response);

        if (strpos($type, 'urlencoded') !== false) {
            parse_str($content, $parsed);

            return $parsed;
        }

        // Attempt to parse the string as JSON regardless of content type,
        // since some providers use non-standard content types. Only throw an
        // exception if the JSON could not be parsed when it was expected to.
        try {
            return $this->parseJson($content);
        } catch (UnexpectedValueException $e) {
            if (strpos($type, 'json') !== false) {
                throw $e;
            }

            return $content;
        }
    }
1039264
public function parseData(array $response)
    {
        $key = str_replace('.', '_', $this->getMethod()) . '_response';
        return array_key_exists($key, $response) ? $response[$key] : null;
    }
653790
protected function parseResponse(ResponseInterface $response): string
    {
        $data = \GuzzleHttp\json_decode($response->getBody(), true);
        isset($data[0]) ? $this->setNotificationData($data) : $this->setData($data);
        $message = sprintf('HTTP %s Error %s', $response->getStatusCode(), $this->data['title']);
        if (isset($this->data['description'])) {
            $message .= sprintf(': %s', $this->getDescription());
        }

        return $message;
    }
1305953
public function format(array $response)
    {
        $car = '<br />';
        $format = '';
        foreach ($response as $category) {
            $format .= '<div class="category"><span class="title">'
            . ApiTools::safeString($category->getTitle()) . '</span>'
            .$car . 'pageid: <span class="pageid">' . $category->getPageid() . '</span>'
            .$car . 'files: ' . $category->getFiles()
            .$car . 'pages: ' . $category->getPages()
            .$car . 'subcats: ' . $category->getSubcats()
            .$car . 'size: ' . $category->getSize()
            .$car . 'hidden: ' . ($category->getHidden() ? 'true' : 'false')
            .'</div>';
        }
        return $format;
    }