Output the response body.

@param ResponseInterface $response The response.
@param string $compression Compression to use: 'bzip2' or 'gzip'.
421370
protected function serveBody(ResponseInterface $response, $compression = null)
    {
        $body = $response->getBody();
        $body->rewind();
        $out = fopen('php://output', 'wb');
        if ($compression == 'bzip2') {
            fwrite($out, bzcompress($body->getContents()));
        } elseif ($compression == 'gzip') {
            fwrite($out, gzencode($body->getContents()));
        } else {
            while (! $body->eof()) {
                fwrite($out, $body->read(8192));
            }
        }
        fclose($out);
        $body->close();
    }
991179
public function sealResponse(
        ResponseInterface $response,
        SealingPublicKey $publicKey
    ): ResponseInterface {
        $sealed = Simple::seal(
            (string) $response->getBody(),
            $publicKey
        );
        return $response->withBody(
            $this->adapter->stringToStream(
                Base64UrlSafe::encode($sealed)
            )
        );
    }
120663
public function sendResponseHttpHeaders(ResponseInterface $response):void
    {
        // checking
        if (headers_sent()) {
            throw new ResponseSenderException("A response has already been sent to the web browser",
                $this);
        }

        // removing PHP native HTTP headers (if enabled)
        if ($this->removePhpHttpHeaders) {
            foreach (headers_list() as $header) {
                header_remove(explode(":", $header)[0]);
            }
        }

        // sending response HTTP headers
        $this->sendHttpVersionHeader(
            $response->getProtocolVersion(),
            $response->getStatusCode(),
            $response->getReasonPhrase()
        );
        $this->sendHttpHeaders($this->listResponseHeaders($response));
    }
1365150
public function send(ResponseInterface $response)
	{	
	    
		// Send response
		if (!headers_sent()) {
			// Status
			header(sprintf(
					'HTTP/%s %s %s',
					$response->getProtocolVersion(),
					$response->getStatusCode(),
					$response->getReasonPhrase()
					));
			
			// Headers
			foreach ($response->getHeaders() as $name => $values) {
				foreach ($values as $value) {
					header(sprintf('%s: %s', $name, $value), false);
				}
			}
		}
		
		// Body
		if (!$this->isEmptyResponse($response)) {
			$body = $response->getBody();
			if ($body->isSeekable()) {
				$body->rewind();
			}
			$chunkSize = Config::getCommon('response.chunkSize', 4096);
			$contentLength  = $response->getHeaderLine('Content-Length');
			if (!$contentLength) {
				$contentLength = $body->getSize();
			}
			
			if (isset($contentLength)) {
				$amountToRead = $contentLength;
				while ($amountToRead > 0 && !$body->eof()) {
					$data = $body->read(min($chunkSize, $amountToRead));
					echo $data;
					
					$amountToRead -= strlen($data);
					
					if (connection_status() != CONNECTION_NORMAL) {
						break;
					}
				}
			} else {
				while (!$body->eof()) {
					echo $body->read($chunkSize);
					if (connection_status() != CONNECTION_NORMAL) {
						break;
					}
				}
			}
		}
	}
282328
protected function getBodyContentLength( ResponseInterface $response ) {
		$content_length = $response->getHeaderLine( 'Content-Length' );

		if ( ! $content_length ) {
			$body = $this->getBody( $response );
			$content_length = $body->getSize();
		}

		if ( ! is_numeric( $content_length ) ) {
			$content_length = 0;
		}

		return (integer) $content_length;
	}
143759
public function output(\stdClass $object, ResponseInterface $response) {
        $response->setContentType('application/json');
        $response->setJsonContent($object);
        $response->send();
    }
67382
public function processResponse(ResponseInterface $response)
    {
        if (!$response instanceof Response
            || !$this->getRequest()
        ) {
            return;
        }

        $response = $this->handleResponse($response);
        $this->renderResponse($response);
        $this->terminateApp();
    }
1367363
protected function render(ResponseInterface $response)
    {
        $stream = new Stream('php://memory', 'rw+');
        $content = $this->getEngine()
            ->parse($this->getTemplate())
            ->process($this->getData())
        ;
        $stream->write($content);

        $response = $response->withBody($stream);
        return $response;
    }
328712
public function sendResponse(ResponseInterface $response): void
    {
        // Send all the headers
        \http_response_code($response->getStatusCode());
        foreach ($response->getHeaders() as $headerName => $headerValues) {
            /** @var string[] $headerValues */
            foreach ($headerValues as $headerValue) {
                \header("$headerName: $headerValue", false);
            }
        }

        // Get the body, rewind it if possible
        $body = $response->getBody();
        if ($body->isSeekable()) {
            $body->rewind();
        }

        // If the body is not readable do not send any body to the client
        if (!$body->isReadable()) {
            return;
        }

        // Send the body (by chunk if specified in the container using streamReadLength value)
        if (null === $this->streamReadLength) {
            echo $body->__toString();

            return;
        }

        while (!$body->eof()) {
            echo $body->read($this->streamReadLength);
        }
    }
197246
private function send(RequestInterface $request, ResponseInterface $response)
    {
        // Send headers if no headers has been sent before this
        if (!headers_sent()) {
            // Send headers
            $this->sendHeaders($response);
        }

        // Check if we have any content to flush
        if (ob_get_level() > 1) {
            // Flush (send) the buffer that contains output that the application has generated
            while (ob_get_level() >= $this->outputBufferLevel) {
                ob_end_flush();
            }
        }

        // Set buffer level to null
        $this->outputBufferLevel = null;

        // Make sure it wasn't a HEAD request
        if ($request->getMethod() !== 'HEAD') {
            // Send the body to the client by echoing it
            echo $response->getBody();
        }
    }
218388
private function sendResponse($response)
    {
        if ($response instanceof ResponseInterface) {
            $response->sendContent();
        } else {
            echo $this->response->send($response);
        }
    }
1842
public function emit(ResponseInterface $response, int $bufferSize = 4096){
        while(0 < ob_get_level()){
            ob_end_flush();
        }

        if(!headers_sent($file, $line)){
            $this->emitHttpStatus($response);
            $this->emitHeaders($response);
        }

        if(0 < $response->getBody()->getSize()){
            $this->emitBody($response, $bufferSize);
        }
    }
130303
protected function createLaravelResponse(ResponseInterface $response)
    {
        return new Response(
            (string) $response->getBody(),
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }
961781
protected function dispatchOnResponse(ResponseInterface $response): ResponseInterface
    {
        $responseEvent = new ResponseEvent($response);
        $this->dispatcher->dispatch($this->responseEvent, $responseEvent);

        return $responseEvent->getResponse();
    }
403366
public function output(ResponseInterface $response, bool $emulate = false)
    {
        $code = $response->getStatus();
        $headers = $response->getHeaders();
        $body = $response->getContent();

        //make sure it's a string
        $body = (string) $body;

        if ($emulate) {
            $this->successful = true;
            return $body;
        }

        //now map it out
        call_user_func($this->map['output'], $code, $headers, $body);

        $this->successful = true;

        return $this;
    }
927784
protected function finalizeResponse(ResponseInterface $response) : ResponseInterface
    {
        // stop PHP sending a Content-Type automatically
        ini_set('default_mimetype', '');
        if ($this->isEmptyResponseCode($response->getStatusCode())) {
            return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
        }

        return $response;
    }
15639
public function sendBody( ResponseInterface $response, $chunk_size = 4096 ) {
		$body = $this->getBody( $response );
		$content_length = $this->getBodyContentLength( $response );

		if ( $content_length > 0 ) {
			$this->sendBodyWithLength( $body, $content_length, $chunk_size );
		} else {
			$this->sendBodyWithoutLength( $body, $chunk_size );
		}
	}