Merges the contents of this response with ``$response`` and returns a new
:php:class:`Response` instance.

@param Response $response

@return Response

@throws IncompatibleResponseException
320071
public function merge(Response $response)
    {
        $meta       = $response->getRaw('meta');
        $data       = $response->get();
        $pagination = $response->hasPages()
            ? $response->getRaw('pagination')
            : [];

        $old = $this->get();

        if ($this->isCollection($old) && $this->isCollection($data)) {
            $old = !($old instanceof Collection) ?: $old->toArray();
            $new = !($data instanceof Collection) ?: $data->toArray();

            return new Response($meta, array_merge($old, $new), $pagination);
        }

        if ($this->isRecord($old) && $this->isRecord($data)) {
            return new Response($meta, [$old, $data], $pagination);
        }

        throw new IncompatibleResponseException('The response contents cannot be merged');
    }
1113435
protected function splitResponseToHeadersArrayAndBody(string $response): HttpResponseInterface
    {
        //        $tmp = explode("\r\n\r\n", $response, 2);
        //        var_export($tmp);
        list($headers, $this->body) = explode("\r\n\r\n", $response, 2);

        $this->headers = $this->getHeaderArray($headers);

        return $this;
    }
172
public function addResponse($key, array $response)
    {
        $originalRequest = isset($this->request[$key]) ? $this->request[$key] : null;
        $responseBody = isset($response['body']) ? $response['body'] : null;
        $responseError = isset($response['error']) ? $response['error'] : null;
        $responseMethod = isset($response['method']) ? $response['method'] : null;

        $this->responses[$key] = new Response($originalRequest, $responseBody, $responseError, $responseMethod);
    }
961344
public static function create($response)
    {
        if (is_array($response)) {
            return new Response($response[0], $response[1]);
        } elseif (is_int($response)) {
            return new Response($response);
        } elseif (is_string($response)) {
            return new Response(200, $response);
        } elseif ($response instanceof Response) {
            return $response;
        }
        return new Response;
    }
231674
protected function buildJsonpResponse(Response $response) {
		$content     = (string)$response->getBody();
		$contentType = $response->getHeaderLine('Content-Type');

		if (strpos($contentType, 'application/json') === false) {
			$content = '"' . $content . '"';
		}

		$callback = "{$this->callbackName}({$content});";

		$newResponse = new Response(200);
		$newResponse->getBody()->write($callback);

		return $newResponse->withHeader('Content-Type', 'application/javascript');
	}
53975
public function render($content, Response $response)
    {
        $response->setStatusCode(Response::HTTP_OK);
        $response->headers->set('Content-Type', 'application/json');
        $response->setContent(json_encode($content));

        return $response;
    }
1371358
public function addResponse(RequestInterface $request, ResponseInterface $response): self
    {
        $new = clone $this;
        $new->responses->attach($request, $response);

        return $new;
    }
878321
public function handleResponse(Request $request, Response $response)
    {
        if ($response->getStatusCode() == 422) {
            $errors = $response->getOriginalContent()['validation_errors'];

            throw new HttpResponseException(
                redirect()->back()->withInput($request->input())->withErrors($errors)
            );
        }

        if ($response->getStatusCode() == 403) {
            abort(403);
        }

        return $response->isNotFound() ? abort(404) : $response->getOriginalContent();
    }
1006395
protected function getResponseData(Response $response)
    {
        if ($response instanceof JsonResponse) {
            /** @var $response JsonResponse */
            return $response->getData(true) ?: [];
        }

        $content = $response->getContent();

        return json_decode($content, true) ?: false;
    }
570713
protected function _processResponse(Response $response): ResponseSet
    {
        $responseData = $response->getData();

        $actions = $this->getActions();

        $bulkResponses = [];

        if (isset($responseData['items']) && \is_array($responseData['items'])) {
            foreach ($responseData['items'] as $key => $item) {
                if (!isset($actions[$key])) {
                    throw new InvalidException('No response found for action #'.$key);
                }

                $action = $actions[$key];

                $opType = \key($item);
                $bulkResponseData = \reset($item);

                if ($action instanceof AbstractDocumentAction) {
                    $data = $action->getData();
                    if ($data instanceof Document && $data->isAutoPopulate()
                        || $this->_client->getConfigValue(['document', 'autoPopulate'], false)
                    ) {
                        if (!$data->hasId() && isset($bulkResponseData['_id'])) {
                            $data->setId($bulkResponseData['_id']);
                        }
                        if (isset($bulkResponseData['_version'])) {
                            $data->setVersion($bulkResponseData['_version']);
                        }
                    }
                }

                $bulkResponses[] = new BulkResponse($bulkResponseData, $action, $opType);
            }
        }

        $bulkResponseSet = new ResponseSet($response, $bulkResponses);

        if ($bulkResponseSet->hasError()) {
            throw new BulkResponseException($bulkResponseSet);
        }

        return $bulkResponseSet;
    }
478198
protected function respond($response)
    {
        if ($response === null) {
            return $this->mapResponse(true, []);
        }

        if (!empty($response) && !isset($response[0])) {
            $success = null === Arr::get($response, 'error_code');

            return $this->mapResponse($success, $response);
        }

        $responses = [];

        foreach ($response as $responseItem) {
            $success = null === Arr::get($responseItem, 'error_code');

            $responses[] = $this->mapResponse($success, $responseItem);
        }

        return $responses;
    }
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);
    }
772930
protected function processResult(Response $response)
    {
        $content = $response->getContent();
        if (strpos($content, "callback(") === 0) {
            $count = 0;
            $jsonData = preg_replace('/^callback\(\s*(\\{.*\\})\s*\);$/is', '\1', $content, 1, $count);
            if ($count === 1) {
                $response->setContent($jsonData);
            }
        }
    }
187222
protected function respond($response)
    {
        $success = Arr::get($response, 'success');

        return $this->mapResponse($success, $response);
    }
13852
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if (
            (isset($jsonData['errCode']) && 0 === $jsonData['errCode'])
            || (isset($jsonData['retcode']) && 0 === $jsonData['retcode'])
        ) {
            return true;
        }
        if (isset($jsonData['retcode']) && 103 === $jsonData['retcode']) {
            throw new Code103ResponseException($response);
        }

        return false;
    }
1032919
protected function filterResponse($response)
    {
        // this is needed to support StreamedResponse
        ob_start();
        $response->sendContent();
        $content = ob_get_clean();

        return new DomResponse($content, $response->getStatusCode(), $response->headers->all());
    }
1071495
public static function fromString($response)
	{
		$code 	 = self::extractCode($response);
		$headers = self::extractHeaders($response);
		$body 	 = self::extractBody($response);
		$version = self::extractVersion($response);
		$message = self::extractMessage($response);
		
		# FIX FOR MULTIPLE HTTP RESPONSE CODE RETURNED BY SERVER 
		if ($code === 100 && count($headers) === 0 && self::extractCode($body)) {
			return self::fromString($body);
		}
		
		return new static($code, $headers, $body, $version, $message);
	}