Sends response to client.

@param Response $response
@return void
762110
public function send(Response $response): void
    {
        // send http header:
        $httpHeader = sprintf(
            'HTTP/%s %d %s',
            $response->getProtocolVersion(),
            $response->getStatus(),
            $response->getStatusMessage()
        );
        header($httpHeader, true);

        // send additional headers:
        foreach ($response->getHeaders() as $name => $value) {
            header(sprintf('%s: %s', $name, $value), true);
        }

        // send body:
        echo $response->getBody();
    }
1133182
public function behave(Response $response)
    {
        return new Response(
            json_decode($response->content(), true),
            $response->contentType(),
            $response->error(),
            $response->errorCode(),
            $response->headerLines(),
            $response->statusCode()
        );
    }
888362
private function sendResponse(Auth_OpenID_ServerResponse $response) {

		SimpleSAML\Logger::debug('openidProvider::sendResponse');

		$webresponse = $this->server->encodeResponse($response);

		if ($webresponse->code !== 200) {
			header('HTTP/1.1 ' . $webresponse->code, TRUE, $webresponse->code);
		}

		foreach ($webresponse->headers as $k => $v) {
			header($k . ': ' . $v);
		}
		header('Connection: Close');

		print($webresponse->body);
		exit(0);
	}
1023112
private function send(Response $response, Request $request = null): \Generator
    {
        \assert($this->client, "The driver has not been setup; call setup first");

        if ($this->lastWrite) {
            yield $this->lastWrite; // Prevent writing another response until the first is finished.
        }

        $shouldClose = false;

        $protocol = $request !== null ? $request->getProtocolVersion() : "1.0";

        $status = $response->getStatus();
        $reason = $response->getReason();

        $headers = $this->filter($response, $protocol, $request ? $request->getHeaderArray("connection") : []);

        $chunked = !isset($headers["content-length"])
            && $protocol === "1.1"
            && $status >= Status::OK;

        if (!empty($headers["connection"])) {
            foreach ($headers["connection"] as $connection) {
                if (\strcasecmp($connection, "close") === 0) {
                    $chunked = false;
                    $shouldClose = true;
                }
            }
        }

        if ($chunked) {
            $headers["transfer-encoding"] = ["chunked"];
        }

        $buffer = "HTTP/{$protocol} {$status} {$reason}\r\n";
        $buffer .= Rfc7230::formatHeaders($headers);
        $buffer .= "\r\n";

        if ($request !== null && $request->getMethod() === "HEAD") {
            ($this->write)($buffer, $shouldClose);
            return;
        }

        $chunk = ""; // Required for the finally, not directly overwritten, even if your IDE says otherwise.
        $body = $response->getBody();
        $streamThreshold = $this->options->getStreamThreshold();

        try {
            while (null !== $chunk = yield $body->read()) {
                if (!($length = \strlen($chunk))) {
                    continue;
                }

                if ($chunked) {
                    $chunk = \sprintf("%x\r\n%s\r\n", $length, $chunk);
                }

                if (\strlen($buffer) < $streamThreshold) {
                    $buffer .= $chunk;
                    continue;
                }

                // Initially the buffer won't be empty and contains the headers.
                // We save a separate write or the headers here.
                $promise = ($this->write)($buffer);

                $buffer = $chunk;
                $chunk = ""; // Don't use null here, because of the finally

                yield $promise;
            }

            if ($buffer !== "" || $chunked || $shouldClose) {
                yield ($this->write)($chunked ? "{$buffer}0\r\n\r\n" : $buffer, $shouldClose);
            }
        } catch (ClientException $exception) {
            return; // Client will be closed in finally.
        } finally {
            if ($chunk !== null) {
                $this->client->close();
            }
        }
    }
439684
public function setResponse($response)
    {
        $xml = simplexml_load_string($response);
        if (!empty($xml->error)) {
            $this->message = (string) $xml->error;
        }
    }
175462
public function respond(ResponseInterface $response)
    {
        if (headers_sent()) {
            throw new HeadersAlreadySentException('Headers were already sent');
        }

        /** @var PsrResponseInterface $r */
        $r = $response;

        $status = sprintf('HTTP/%s %s %s', $r->getProtocolVersion(), $r->getStatusCode(), $r->getReasonPhrase());
        header($status, TRUE);

        foreach ($r->getHeaders() as $name => $values) {
            $header = sprintf('%s: %s', $name, $r->getHeaderLine($name));
            header($header, FALSE);
        }

        echo $r->getBody();
    }
1281166
protected function sendResponse(Response $response, Throwable $exception): void
	{
		if($exception instanceof MethodNotAllowedException)
		{
			$this->response->getHeaders()->add('Allow', implode(',', $exception->getAllowedMethods()));
		}

		$response->send();
	}
378644
public function send()
    {
        $this->request = $this->client->createRequest(
            $this->method,
            $this->host . $this->resource
        );

        // set headers
        foreach ($this->headers as $header => $value) {
            $this->request->setHeader($header, $value);
        }

        // set body
        if (!empty($this->body)) {
            $this->request->setBody($this->body);
        }

        try {
            // finally send the request
            $this->response = $this->client->send($this->request);
        } catch (RequestException $e) {
            // if the response is an 40x or a 50x then it will throw an exception
            // we catch and get the response stored on the request object
            $this->response = $e->getResponse();
        }

        $this->sent = true;
    }
771593
public function afterSend($response)
    {
        $this->client->afterSend($this, $response);

        $event = new RequestEvent();
        $event->request = $this;
        $event->response = $response;
        $this->trigger(self::EVENT_AFTER_SEND, $event);
    }
194062
public function respond(ResponseInterface $response)
    {
        $this->httpClient->respond(
            $response->getStatusCode(),
            $response->getBody()->__toString(),
            $response->getHeaders()
        );
    }
934817
public function sendResponse()
    {
        $this->sendHeaders();

        if ($this->isException() && $this->renderExceptions())
        {
            $exceptions = '';
            foreach ($this->getException() as $e)
            {
                $exceptions .= $e->__toString() . "\n";
            }
            echo $exceptions;
            return;
        }

        $this->outputBody();
    }
451849
protected void sendServerResponse(HttpMessage response) {
        designer.http().server(httpServer).send()
                .response(response.getStatusCode())
                .message(response);
    }
958461
public function setRawResponse($response)
    {
        $parts = explode("\r\n\r\n", $response);

        if (count($parts) == 2) {
            $matches = array();
            $this->responseBody = $parts[1];

            if (preg_match_all(
                '/(HTTP\/[1-9]\.[0-9]\s+(?<statusCode>\d+)\s+(?<statusMessage>.*)'.
                        "|(?<headerName>[^:]+)\\s*:\\s*(?<headerValue>.*))\r\n/m",
                    $parts[0], $matches)) {
                foreach ($matches['statusCode'] as $offset => $match) {
                    if (!empty($match)) {
                        $this->statusCode = (int) $match;
                        $this->statusMessage = $matches['statusMessage'][$offset];
                        break;
                    }
                }

                foreach ($matches['headerName'] as $offset => $name) {
                    if (!empty($name)) {
                        $key = strtolower($name);
                        $header = array('name' => $name,
                            'value' => $matches['headerValue'][$offset],
                        );

                        if (isset($this->responseHeader[$key])) {
                            if (isset($this->responseHeader[$key]['name'])) {
                                $this->responseHeader[$key] = array(
                                    $this->responseHeader[$key],
                                );
                            }

                            $this->responseHeader[$key][] = $header;
                        } else {
                            $this->responseHeader[$key] = $header;
                        }
                    }
                }
            }
        } else {
            $this->responseBody = $response;
        }
    }
983726
private function parseResponse($response) {
        $response = trim($response);
        $this->responseStatus = (int) substr($response, 0, 3);
        $this->response = substr($response, 4);
    }
1323219
public static function sendResponse(ResponseInterface $response)
    {
        header('HTTP/'.$response->getHttpVersion().' '.$response->getStatus().' '.$response->getStatusText());
        foreach ($response->getHeaders() as $key => $value) {
            foreach ($value as $k => $v) {
                if (0 === $k) {
                    header($key.': '.$v);
                } else {
                    header($key.': '.$v, false);
                }
            }
        }

        $body = $response->getBody();
        if (null === $body) {
            return;
        }

        if (is_callable($body)) {
            $body();

            return;
        }

        $contentLength = $response->getHeader('Content-Length');
        if (null !== $contentLength) {
            $output = fopen('php://output', 'wb');
            if (is_resource($body) && 'stream' == get_resource_type($body)) {
                if (PHP_INT_SIZE !== 4) {
                    // use the dedicated function on 64 Bit systems
                    stream_copy_to_stream($body, $output, (int) $contentLength);
                } else {
                    // workaround for 32 Bit systems to avoid stream_copy_to_stream
                    while (!feof($body)) {
                        fwrite($output, fread($body, 8192));
                    }
                }
            } else {
                fwrite($output, $body, (int) $contentLength);
            }
        } else {
            file_put_contents('php://output', $body);
        }

        if (is_resource($body)) {
            fclose($body);
        }
    }
1235072
public function bind($response) {
		$this->_response = $response;
		$this->_response->headers += $this->_headers;

		foreach ($this->_queue as $message) {
			$this->_write($message);
		}
	}
1224513
private function sendHeaders(ResponseInterface $response)
    {
        // Set proper protocol, status code (and reason phrase) header
        if ($response->getReasonPhrase()) {
            header(sprintf(
                'HTTP/%s %d %s',
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                $response->getReasonPhrase()
            ));
        } else {
            header(sprintf(
                'HTTP/%s %d',
                $response->getProtocolVersion(),
                $response->getStatusCode()
            ));
        }

        // Loop through all headers
        foreach ($response->getHeaders() as $name => $values) {
            // Sanitize header name
            $name  = $this->sanitizeHeaderName($name);
            // First iteration, if more than one header with the same name
            // exists the $first parameter to the header method will indicate
            // if a second (etc) header should replace the previous one or
            // if multiple headers with the same name should be sent
            $first = true;
            foreach ($values as $value) {
                // Send header
                header(sprintf('%s: %s', $name, $value), $first);
                $first = false;
            }
        }
    }