This method is used to retrieve an url from the frontend and decode the response.

@param string $url
@param PageIndexerResponse $response
@return mixed
504955
protected function getUrlAndDecodeResponse($url, PageIndexerResponse $response)
    {
        $headers = $this->getHeaders();
        $rawResponse = $this->getUrl($url, $headers, $this->timeout);
        // convert JSON response to response object properties
        $decodedResponse = $response->getResultsFromJson($rawResponse->getBody()->getContents());

        if ($rawResponse === false || $decodedResponse === false) {
            $this->logger->log(
                SolrLogManager::ERROR,
                'Failed to execute Page Indexer Request. Request ID: ' . $this->requestId,
                [
                    'request ID' => $this->requestId,
                    'request url' => $url,
                    'request headers' => $headers,
                    'response headers' => $rawResponse->getHeaders(),
                    'raw response body' => $rawResponse->getBody()->getContents()
                ]
            );

            throw new \RuntimeException('Failed to execute Page Indexer Request. See log for details. Request ID: ' . $this->requestId, 1319116885);
        }
        return $decodedResponse;
    }
1198383
private function getRemoteData(string $url): ResponseInterface
    {
        $errno  = 0;
        $errstr = '';

        ini_set('user_agent', $this->loader->getUserAgent());

        $this->urlParts = parse_url($url);
        $timeout        = $this->loader->getTimeout();

        $this->stream = @fsockopen(
            $this->urlParts['host'],
            $this->getPort(),
            $errno,
            $errstr,
            $timeout
        );

        if (false === $this->stream) {
            throw new Exception('could not initialize the socket to load the data');
        }

        stream_set_timeout($this->stream, $timeout);
        stream_set_blocking($this->stream, true);

        if (isset($this->urlParts['query'])) {
            $this->urlParts['path'] .= '?' . $this->urlParts['query'];
        }

        $out = sprintf(
            Loader::REQUEST_HEADERS,
            $this->urlParts['path'],
            $this->urlParts['host'],
            $this->loader->getUserAgent()
        );

        fwrite($this->stream, $out);

        $response = '';
        while ($this->isValid()) {
            $response .= $this->getLine() . "\n";
        }

        $this->close();

        $response   = str_replace("\r\n", "\n", $response);
        $response   = explode("\n\n", $response);
        $rawHeaders = explode("\n", trim(array_shift($response)));
        $response   = trim(implode("\n\n", $response));
        $headers    = [];
        $code       = 200;

        foreach ($rawHeaders as $rawHeader) {
            $parts  = explode(':', $rawHeader, 2);
            $header = $parts[0];

            if ('http/' === mb_substr(mb_strtolower($header), 0, 5)) {
                $tmp_status_parts = explode(' ', $header, 3);
                $code             = $tmp_status_parts[1];
            }

            if (isset($parts[1])) {
                $value = trim($parts[1]);
            } else {
                $value = '';
            }

            $headers[$header] = $value;
        }

        return new Response($code, $headers, $response);
    }
1356668
protected function extractLinkHeader( $response ) {
		if ( is_object( $response ) && property_exists( $response, 'headers' ) && is_array( $response->headers ) && isset( $response->headers['Link'] ) ) {
			return $response->headers['Link'];
		}
		if ( is_array( $response ) && isset( $response['headers'], $response['headers']['Link'] ) ) {
			return $response['headers']['Link'];
		}
		return '';
	}
454570
private function injectPager(array $response, $method, $url, array $params = [])
    {
        while (next($response)) {
            if ('paging' === key($response)) {
                prev($response);
                break;
            }
        }

        $pageableKey = key($response);

        $response[$pageableKey] = new Pager($response, $pageableKey, $this->client, $method, $url, $params);

        reset($response);

        return $response;
    }
631118
public function fromResponse(HttpResponseInterface $response)
    {
        return $this->createResponse(
            $response->getStatusCode(),
            $response->getHeaders(),
            JsonRpc\json_decode((string) $response->getBody(), true) ?: []
        );
    }
1331579
public static function getPagination(ResponseInterface $response): ?array
    {
        if (!$response->hasHeader('Link')) {
            return null;
        }

        $header     = self::getHeader($response, 'Link');
        $pagination = [];
        foreach (explode(',', $header) as $link) {
            preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match);

            if (3 === count($match)) {
                $pagination[$match[2]] = $match[1];
            }
        }

        return $pagination;
    }
602827
protected function response(Response $response)
    {
        $content = $response->getContent();

        if (is_string($content) &&
            is_array(json_decode($content, true)) &&
            json_last_error() === JSON_ERROR_NONE) {
            return $this->contentWithinLimits($content)
                    ? $this->hideParameters(json_decode($content, true), Telescope::$hiddenResponseParameters)
                    : 'Purged By Telescope';
        }

        if ($response instanceof RedirectResponse) {
            return 'Redirected to '.$response->getTargetUrl();
        }

        if ($response instanceof IlluminateResponse && $response->getOriginalContent() instanceof View) {
            return [
                'view' => $response->getOriginalContent()->getPath(),
                'data' => $this->extractDataFromView($response->getOriginalContent()),
            ];
        }

        return 'HTML Response';
    }
1060405
protected function response($response) {
    // Check for HTTP response error codes.
    if ($this->client->error) {
      $this->onErrorResponse(
        $this->client->errorCode,
        $this->client->errorMessage,
        $response
      );
    }
    else {
      $this->onSuccessfulResponse($response);
    }
    return $response;
  }
847149
public function validateResponse($url, $response)
	{
		if (strpos($url, 'verify_credentials') === false && $response->code != 200)
		{
			$error = json_decode($response->body);

			if (property_exists($error, 'error'))
			{
				throw new \DomainException($error->error);
			}

			$error = $error->errors;

			throw new \DomainException($error[0]->message, $error[0]->code);
		}
	}
157460
public static function decodeHttpResponse($response) {
    $code = $response->getResponseHttpCode();
    $body = $response->getResponseBody();
    $decoded = null;
    
    if ($code != '200' && $code != '201' && $code != '204') {
      $decoded = json_decode($body, true);
      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
      if ($decoded != null && isset($decoded['error']['message'])  && isset($decoded['error']['code'])) {
        // if we're getting a json encoded error definition, use that instead of the raw response
        // body for improved readability
        $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
      } else {
        $err .= ": ($code) $body";
      }
      throw new Service\Exception($err, $code);
    }
    
    // Only attempt to decode the response, if the response code wasn't (204) 'no content'
    if ($code != '204') {
      $decoded = json_decode($body, true);
      if ($decoded == null) {
        throw new Service\Exception("Invalid json in service response: $body");
      }
    }
    return $decoded;
  }
147445
public static function parse(string $response) : Response
    {
        $responseObject = new Response();

        if (preg_match('/^HTTP\/([0-9]\.[0-9]) ([0-9]{3}) .*\r\n/', $response, $matches) !== 1) {
            throw new \RuntimeException('Could not parse response (error 1).');
        }

        [$line, $protocolVersion, $statusCode] = $matches;

        $responseObject->setProtocolVersion($protocolVersion);
        $responseObject->setStatusCode((int) $statusCode);

        $response = substr($response, strlen($line));

        for (;;) {
            $pos = strpos($response, Message::CRLF);
            if ($pos === false) {
                throw new \RuntimeException('Could not parse response (error 2).');
            }

            if ($pos === 0) {
                break;
            }

            $header = substr($response, 0, $pos);

            if (preg_match('/^(\S+):\s*(.*)$/', $header, $matches) !== 1) {
                throw new \RuntimeException('Could not parse response (error 3).');
            }

            [$line, $name, $value] = $matches;

            if (strtolower($name) === 'set-cookie') {
                $responseObject->setCookie(Cookie::parse($value));
            } else {
                $responseObject->addHeader($name, $value);
            }

            $response = substr($response, strlen($line) + 2);
        }

        $body = substr($response, 2);

        $responseObject->setContent($body);

        return $responseObject;
    }
1292541
protected function decodeData(ResponseObject $response)
    {
        $resultArray = json_decode($response->getBody(), true);
        if ($resultArray === null) {
            throw new JsonException('Failed to decode response', json_last_error());
        }

        return $resultArray;
    }
501447
public function decryptResponse($response)
    {
        if (!is_string($response)) {
            return $response;
        }

        if ($this->usesEncryption()) {
            return json_decode(
                json_encode(
                    JWT::decode(
                        $response,
                        $this->encryptionKey,
                        array($this->encryptionAlgorithm)
                    )
                ),
                true
            );
        }

        throw EncryptionConfigurationException::undeterminedEncryption();
    }
201694
protected HttpProxyResponse decodeResponse(final String response)
            throws Exception {
        LOGGER.debug("  parseResponse()");

        // Break response into lines
        String[] responseLines = response.split(HttpProxyConstants.CRLF);

        // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
        // BUG FIX : Trimed to prevent failures with some proxies that add 
        // extra space chars like "Microsoft-IIS/5.0" ...
        String[] statusLine = responseLines[0].trim().split(" ", 2);

        if (statusLine.length < 2) {
            throw new Exception("Invalid response status line (" + statusLine
                    + "). Response: " + response);
        }

        // Status code is 3 digits
        if (statusLine[1].matches("^\\d\\d\\d")) {
            throw new Exception("Invalid response code (" + statusLine[1]
                    + "). Response: " + response);
        }

        Map<String, List<String>> headers = new HashMap<>();

        for (int i = 1; i < responseLines.length; i++) {
            String[] args = responseLines[i].split(":\\s?", 2);
            StringUtilities.addValueToHeader(headers, args[0], args[1], false);
        }

        return new HttpProxyResponse(statusLine[0], statusLine[1], headers);
    }
1120115
protected function getUrl($url, $headers, $timeout): ResponseInterface
    {
        try {
            $options = $this->buildGuzzleOptions($headers, $timeout);
            $response = $this->requestFactory->request($url, 'GET', $options);
        } catch (ClientException $e) {
            $response = $e->getResponse();
        } catch (ServerException $e) {
            $response = $e->getResponse();
        }

        return $response;
    }
475217
private function getRemoteData(string $url): ResponseInterface
    {
        $context      = $this->streamHelper->getStreamContext();
        $stream       = @fopen($url, 'rb', false, $context);

        if (false === $stream) {
            throw new Exception('could not initialize the connection to load the data');
        }

        $timeout = $this->loader->getTimeout();

        stream_set_timeout($stream, $timeout);
        stream_set_blocking($stream, true);

        $meta    = stream_get_meta_data($stream);
        $headers = [];
        $code    = 200;

        if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
            $headers = $meta['wrapper_data'];

            foreach ($headers as $metaData) {
                if ('http/' === mb_substr(mb_strtolower($metaData), 0, 5)) {
                    $tmp_status_parts = explode(' ', $metaData, 3);
                    $code             = $tmp_status_parts[1];

                    break;
                }
            }
        }

        return new Response($code, $headers, new Stream($stream));
    }
946984
public static function decodeHttpResponse($response) {
    $code = $response->getResponseHttpCode();
    $body = $response->getResponseBody();
    $decoded = null;
    
    if ((intVal($code)) >= 300) {
      $decoded = json_decode($body, true);
      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
      if ($decoded != null && isset($decoded['error']['message'])  && isset($decoded['error']['code'])) {
        // if we're getting a json encoded error definition, use that instead of the raw response
        // body for improved readability
        $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
      } else {
        $err .= ": ($code) $body";
      }

      throw new ServiceException($err, $code, null, $decoded['error']['errors']);
    }
    
    // Only attempt to decode the response, if the response code wasn't (204) 'no content'
    if ($code != '204') {
      $decoded = json_decode($body, true);
      if ($decoded === null || $decoded === "") {
        throw new ServiceException("Invalid json in service response: $body");
      }
    }
    return $decoded;
  }