Build a response
@param StreamInterface $body
@param array $headerArray
@param int $statusCode
@param string $reasonPhrase Status phrase
@return Responses\Response
512955
public function response($body, $headerArray = array(), $statusCode = 200, $reasonPhrase = null)
    {
        $headers = $this->builder->editableHeaders($headerArray);
        return $this->buildResponse($headers, $body, $statusCode, $reasonPhrase);
    }
1247390
protected function readResponse(RequestInterface $request, $socket): ResponseInterface
    {
        $headers = [];
        $reason = null;

        while (false !== ($line = fgets($socket))) {
            if ('' === rtrim($line)) {
                break;
            }
            $headers[] = trim($line);
        }

        $metadatas = stream_get_meta_data($socket);

        if (array_key_exists('timed_out', $metadatas) && true === $metadatas['timed_out']) {
            throw new TimeoutException('Error while reading response, stream timed out', $request, null);
        }

        $parts = explode(' ', array_shift($headers), 3);

        if (count($parts) <= 1) {
            throw new BrokenPipeException('Cannot read the response', $request);
        }

        $protocol = substr($parts[0], -3);
        $status = $parts[1];

        if (isset($parts[2])) {
            $reason = $parts[2];
        }

        // Set the size on the stream if it was returned in the response
        $responseHeaders = [];

        foreach ($headers as $header) {
            $headerParts = explode(':', $header, 2);

            if (!array_key_exists(trim($headerParts[0]), $responseHeaders)) {
                $responseHeaders[trim($headerParts[0])] = [];
            }

            $responseHeaders[trim($headerParts[0])][] = isset($headerParts[1])
                ? trim($headerParts[1])
                : '';
        }

        $response = new Response($status, $responseHeaders, null, $protocol, $reason);
        $stream = $this->createStream($socket, $request, $response);

        return $response->withBody($stream);
    }
1342356
public static function createResponse($body, $mediaType = 'text/html', $code = 200)
    {
        return Factory::createResponse()
            ->withStatus($code)
            ->withHeader('Content-Type', $mediaType)
            ->withBody(Factory::createStream($body));
    }
991337
public function createSymmetricEncryptedResponse(
        int $status,
        string $body,
        SharedEncryptionKey $key,
        array $headers = [],
        string $version = '1.1'
    ): ResponseInterface {
        return new Response(
            $status,
            $headers,
            Base64UrlSafe::encode(Simple::encrypt($body, $key)),
            $version
        );
    }
1088912
final public function withBody(StreamInterface $body): self
    {
        $message = clone $this;
        $message->body = $body;

        return $message;
    }
182073
public SipServletResponse createResponse(final int statusCode, final String reasonPhrase) {
		return createResponse(statusCode, reasonPhrase, true, false);
	}
1203361
public function statusCode($code = null, $reasonPhrase = null)
    {
        if (func_num_args() < 1 || empty($code)) {
            return $this->response->getStatusCode();
        }
        $this->response = $this->response->withStatus($code, $reasonPhrase);
        return $this;
    }
692002
public function setStatusCode(int $statusCode, string $reasonPhrase = null): Response
    {
        $this->status->setCode($statusCode, $reasonPhrase);
        return $this;
    }
84913
protected function getErrorResponse($msg, $errorCode, $statusText, $headers = [])
    {
        return $this->setStatusText($this->statusTexts[$statusText])
                    ->setStatusCode($statusText)
                    ->setStatusMessage(self::ERROR_TEXT)
                    ->setErrorCode($errorCode)
                    ->setErrorMessage($msg)
                    ->respondWithErrorMessage($headers);
    }
849191
public function buildBatch(string $responseMessage): HttpResponseInterface
    {
        $response = $responseMessage;
        $this->splitResponseToHeadersArrayAndBody($response);
        $statusLineArray = explode(' ', trim($this->headers['status'][0]));

        $this->status = (int) $statusLineArray[1];

        //todo: Revisit this:
        if ($this->verboseExtractStatusLine === true) {
            $this->protocol = $statusLineArray[0];

            $this->statusPhrase = $this->decodeGetStatusPhrase($statusLineArray);
        }

        if (in_array((int) $this->status, $this->enabledHttpServerExceptions, true)) {
            // Ignoring this for now.
            // @codeCoverageIgnoreStart
            $this->protocol     = $statusLineArray[0];
            $this->statusPhrase = $this->decodeGetStatusPhrase($statusLineArray);
            throw new ServerException($this->statusPhrase, $this->status);
            // @codeCoverageIgnoreEnd
        }

        //todo: End revisit this:

        return $this;
    }
652769
public function createStreamedResponse(WriterInterface $writer, $status = 200, $headers = array())
    {
        return new StreamedResponse(
            function () use ($writer) {
                $writer->save('php://output');
            },
            $status,
            $headers
        );
    }
747861
private function setStatusCode($code, $reasonPhrase = ''): void
    {
        if (
            !\is_numeric($code) || \is_float($code) ||
            $code < static::MIN_STATUS_CODE_VALUE ||
            $code > static::MAX_STATUS_CODE_VALUE
        ) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid status code "%s"; must be an integer between %d and %d, inclusive',
                \is_scalar($code) ? $code : \gettype($code),
                static::MIN_STATUS_CODE_VALUE,
                static::MAX_STATUS_CODE_VALUE
            ));
        }

        if (!\is_string($reasonPhrase)) {
            throw new \InvalidArgumentException(\sprintf(
                'Unsupported response reason phrase; must be a string, received %s',
                \is_object($reasonPhrase) ? \get_class($reasonPhrase) : \gettype($reasonPhrase)
            ));
        }

        if ($reasonPhrase === '' && isset($this->phrases[$code])) {
            $reasonPhrase = self::$phrases[$code];
        }

        $this->reasonPhrase = $reasonPhrase;
        $this->statusCode = (int) $code;
    }
1065801
protected function addHeaders(ResponseInterface $response, string $body): ResponseInterface
    {
        return $response
            ->andHeader('Content-Type', 'application/json')
            ->andHeader('Content-Length', (string)strlen($body));
    }
113216
protected function generateResponse($statusCode, $json)
    {
        if (empty($json) && $statusCode == Response::REST_SUCCESS_NO_CONTENT) {
            return new Response(array(), $statusCode);
        } else {
            $body = json_decode($json, true);
            if ($body == null) {
                throw new ClientException('Error while sending request to api; Received invalid json: ' . $json, ClientException::SERVER_UNAVAILABLE);
            }
            $response = new Response($body, $statusCode);
            $this->validateServerResponse($response);

            return $response;
        }
    }
782428
function(status, reasonPhrase, headers) {
        var self = this;

        each(headers || reasonPhrase, function(value, name) {
          self.setHeader(name, value);
        });

        return this._super(status, typeof reasonPhrase === 'string' ? reasonPhrase : undefined);
      }
1299647
protected function getCodeResponse($statusCode)
    {
        $this->checkParameters();

        /** @var ResponsesInterface $responses */
        $responses = $this->getIntegration()->getFromContainer(ResponsesInterface::class);
        $outputMediaType = $this->codecMatcher->getEncoderRegisteredMatchedType();

        return $responses->getResponse($statusCode, $outputMediaType, null, $this->supportedExtensions);
    }
1131386
public static function newStream($body = null): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (is_resource($body)) {
            return new Stream($body);
        }

        $stream = new Stream(fopen('php://temp', 'w+'));
        ! empty($body) && $stream->write($body);

        return $stream;
    }