terminate.

@param RequestContract $request
@param ResponseContract $response
@return mixed|void
167991
public function terminate(RequestContract $request, ResponseContract $response)
    {
        $this->terminateMiddleware($request, $response);

        $this->app->terminate();
    }
128064
public function terminate(ServerRequestInterface $request, ResponseInterface $response)
    {
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);
        $applicationEvent->setName(self::EVENT_LIFECYCLE_COMPLETE);
        $this->emit($applicationEvent);

    }
818502
public function stop($data = false, $status = null){

        $this->exit = true;

        if ($status) {
           $this->response->status = $status;
        }

        if ($data) {
            $this->response->body = $data;
        }

        if (\is_numeric($data) && isset(self::$statusCodes[$data])) {

            $this->response->status = $data;

            if ($this->response->mime == 'json') {
                $this->response->body = \json_encode(['error' => self::$statusCodes[$data]]);
            } else {
                $this->response->body = self::$statusCodes[$data];
            }
        }

        if ($data || $status) {
            echo $this->response->flush();
        }

        exit;
    }
1342114
protected function terminate($context)
    {
        $handler = $context->getMessageHandler();
        $handler->handle($context->getMessageBeingHandled(), $context);
    }
685419
private function doRun(RequestInterface $request, ResponseInterface $response): void
    {
        $throwable = null;

        foreach ($this->plugins as $plugin) {
            if ($plugin->onPreRequest($this, $request, $response)) {
                return;
            }
        }

        try {
            $this->handleRequest($request, $response);
        } catch (\Throwable $throwable) {
            $this->throwableToResponse($throwable, $response);
        }

        if ($response->getStatusCode()->isError()) {
            $this->handleError($request, $response, $throwable);
        }

        foreach ($this->plugins as $plugin) {
            if ($plugin->onPostRequest($this, $request, $response)) {
                return;
            }
        }
    }
180854
public function finish()
    {
        $response = new Response;
        try {
            $file = File::auth();
            if ( $file->exists( self::FILENAME ) )
                unlink( self::FILENAME );
            $response->success = true;
        } catch (Exception $e) {
            Log::error( $e );
        }
        $response->json();
    }
322578
public function execute(Framework $framework, RequestAbstract $request, Response $response)
    {
        $response->setOutputPart('404', 'The requested route is not available. We can\'t execute the request. Route: "' . $request->getRoute() . '"');
    }
430926
protected function sendRequest(RequestContract $request): ResponseContract
    {
        $this->app->instance('request', $this->bindRequestMatcher($request));

        Facade::clearResolvedInstance('request');

        return (new Pipeline($this->app))
            ->send($request)
            ->through(array_merge($this->middleware, $request->matcher()->getCallerMiddleware()))
            ->then(function (RequestContract $request) {
                return $this->toResponse(
                    $this->app->call($request->matcher()->getCallerUses())
                );
            });
    }
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();
            }
        }
    }
1298696
public function shutdown($request, $response)
    {
        $routeMiddlewares = $this->router->getMiddlewares();

        $middlewares = array_merge(array_filter([$routeMiddlewares]), $this->getMiddleware());

        foreach ($middlewares as $middleware) {
            list($name, $parameters) = $this->pipeline->parsePipeString($middleware);

            $instance = $this->container->make($name);

            if (method_exists($instance, 'shutdown')) {
                $instance->shutdown($request, $response);
            }
        }
    }
595934
public function preProcess(Request $request, Response $response): bool
    {
        foreach ($this->preInterceptors as $preInterceptor) {
            if (false === $this->executePreInterceptor($preInterceptor, $request, $response)) {
                return false;
            }
        }

        return true;
    }
257222
private function callLaravelRoute(Request $request): \Symfony\Component\HttpFoundation\Response
    {
        $kernel = app(\Illuminate\Contracts\Http\Kernel::class);
        $response = $kernel->handle($request);
        $kernel->terminate($request, $response);

        return $response;
    }
695841
public function execute(Request $request, Response $response)
    {
      // Open curl handler
      $handle = curl_init();

      // Set header callback
      curl_setopt($handle, CURLOPT_HEADERFUNCTION, array(&$response, 'header'));

      // Do not reuse connection
      curl_setopt($handle, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

      // Clear default "Expect: 100-continue" header
      //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:'));

      // Set custom headers
      if($request->hasHeaders())
      {
        curl_setopt($handle, CURLOPT_HEADER, 0);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $request->getHeaders());
      }

      // Set authentication if needed
      if($request->hasUsername() && $request->hasPassword())
      {
        curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($handle, CURLOPT_USERPWD, $request->getUsername() . ':' . $request->getPassword());
      }

      // Set timeout
      if($request->hasTimeout())
        curl_setopt($handle, CURLOPT_TIMEOUT, $request->getTimeout());

      // Set curl options
      curl_setopt($handle, CURLOPT_URL, $request->getUrl());
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);

      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);

      // Get method
      $method = $request->getMethod();

      if(!method_exists($this, strtolower($method)))
        throw new Exception(__METHOD__ . '; Request method "' .$method . '" not supported');

      // Call request method handler
      call_user_func(array($this, strtolower($method)),  $handle, $request, $response);

      // Execute curl request
      curl_exec($handle);

      // Get info
      $info = curl_getinfo($handle);

      // Set info
      $response->setInfo($info);

      // Close curl handler
      if(!is_null($handle) && is_resource($handle))
        curl_close($handle);
    }
1101623
public function terminate($request, $response)
    {
        $routeMiddlewares = $this->gatherRouteMiddlewares($request);
        foreach (array_merge($routeMiddlewares, $this->middleware) as $middleware) {
            $instance = $this->app->make($middleware);
            if ($instance instanceof TerminableMiddleware) {
                $instance->terminate($request, $response);
            }
        }
        $this->app->terminate();
    }
286813
public function callFinishCallbacks(SymfonyRequest $request, SymfonyResponse $response)
	{
		foreach ($this->finishCallbacks as $callback)
		{
			call_user_func($callback, $request, $response);
		}
	}
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();
    }
460445
public function run(RequestInterface $request, ResponseInterface $response): void
    {
        $this->doRun($request, $response);
        $response->output();
    }