Process an incoming server request and return a response, optionally delegating
response creation to a handler.

@param ServerRequestInterface $request
@param RequestHandlerInterface $handler
@return ResponseInterface
489361
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $this->nextHandler = (isset($this->nextHandler)) ? next($this->handlers) : current($this->handlers);

        // nextHandler is a stack
        if ($this->nextHandler instanceof \Peak\Blueprint\Http\Stack) {
            return $this->returnResponse($this->handleStack($this->nextHandler, $request));
        }

        // no more handlers, look for parent
        if ($this->nextHandler === false && isset($this->parentStack)) {
            return $this->returnResponse($this->parentStack->process($request, $this->parentStack));
        } elseif ($this->nextHandler === false) {
            throw new StackEndedWithoutResponseException($this);
        }

        // resolve nextHandler if not already a object
        $handlerInstance = $this->nextHandler;
        if (is_callable($handlerInstance) || !is_object($handlerInstance)) {
            $handlerInstance = $this->handlerResolver->resolve($this->nextHandler);
        }

        // how to call the handler (MiddlewareInterface or RequestHandlerInterface)
        if ($handlerInstance instanceof MiddlewareInterface) {
            return $this->returnResponse($handlerInstance->process($request, $this));
        } elseif($handlerInstance instanceof RequestHandlerInterface) {
            return $this->returnResponse($handlerInstance->handle($request));
        }

        // at this point, the handler is not good
        throw new InvalidHandlerException($handlerInstance);
    }
417646
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);

        if (stripos($response->getHeaderLine('Content-Type'), $this->mimetype) === 0) {
            $stream = $this->createStream($this->minify((string) $response->getBody()));

            return $response->withBody($stream)
                ->withoutHeader('Content-Length');
        }

        return $response;
    }
813177
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $route = $request->getAttribute('_route');
        if( ! $route || ! ($handler instanceof \Sherpa\Kernel\RequestHandler\RequestHandler) ) {
            return $handler->handle($request);
        }
        foreach($route->getMiddlewares() as $m) {
            $handler->getMiddlewareGroup()->addMiddleware($m['middleware'], $m['priority'], $m['before']);
        }

        return $handler->handle($request);
    }
1070339
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // service data
        $data = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA);

        $method    = $data['method']??"";
        $version   = $data['version']??"";
        $interface = $data['interface']??"";

        /* @var \Swoft\Rpc\Server\Router\HandlerMapping $serviceRouter */
        $serviceRouter  = App::getBean('serviceRouter');
        $serviceHandler = $serviceRouter->getHandler($interface, $version, $method);

        // deliver service data
        $request = $request->withAttribute(self::ATTRIBUTE, $serviceHandler);

        return $handler->handle($request);
    }
712379
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        return $this->pipeline->withRequest($request, function () use ($request, $handler): ResponseInterface {
            return $handler->handle($request);
        });
    }
854735
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $tree = app(Tree::class);

        // Select a locale
        define('WT_LOCALE', I18N::init('', $tree));
        Session::put('language', WT_LOCALE);

        app()->instance(LocaleInterface::class, WebtreesLocale::create(WT_LOCALE));

        return $handler->handle($request);
    }
1139404
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $method = $this->getOverrideMethod($request);

        if (!empty($method) && $method !== $request->getMethod()) {
            $allowed = $this->getAllowedOverrideMethods($request);

            if (!empty($allowed)) {
                if (in_array($method, $allowed)) {
                    $request = $request->withMethod($method);
                } else {
                    return $this->createResponse(405);
                }
            }
        }

        return $handler->handle($request);
    }
240825
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
	{
		[
			'Request-Type' => $type,
			'Response-Headers' => $headers,
		] = $this->analyze($request);

		switch ($type) {
			case self::ERROR_NO_HOST_HEADER:
			case self::ERROR_ORIGIN_NOT_ALLOWED:
			case self::ERROR_METHOD_NOT_SUPPORTED:
			case self::ERROR_HEADERS_NOT_SUPPORTED:
				return Factory::response(403);

			case self::TYPE_REQUEST_OUT_OF_CORS_SCOPE:
				return $handler->handle($request);

			case self::TYPE_PRE_FLIGHT_REQUEST:
				$response = Factory::response(200);

				return self::withCorsHeaders($response, $headers);

			default:
				$response = $handler->handle($request);

				return self::withCorsHeaders($response, $headers);
		}
	}
521139
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $route = $this->router->dispatch($request->getMethod(), rawurldecode($request->getUri()->getPath()));

        if ($route[0] === Dispatcher::NOT_FOUND) {
            return $this->createResponse(404);
        }

        if ($route[0] === Dispatcher::METHOD_NOT_ALLOWED) {
            return $this->createResponse(405)->withHeader('Allow', implode(', ', $route[1]));
        }

        foreach ($route[2] as $name => $value) {
            $request = $request->withAttribute($name, $value);
        }

        $request = $this->setHandler($request, $route[1]);

        return $handler->handle($request);
    }
584978
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $result = $request->getAttribute('routing');

        if (isset($result['error'])) {
            throw HttpErrorException::create($result['error'], [
                'code' => $result['error'],
                'message' => 'Routing not found',
            ]);
        }

        $this->count = 0;
        $this->app->setRequest($request->withoutAttribute('routing'));

        return $this->handle($result['handler'], $result['params']);
    }
322215
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $uri = $request->getUri();
        $path = $this->normalize($uri->getPath());

        if ($this->redirect && ($uri->getPath() !== $path)) {
            return $this->createResponse(301)
                ->withHeader('Location', (string) $uri->withPath($path));
        }

        return $handler->handle($request->withUri($uri->withPath($path)));
    }
34131
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $this->negotiator->process($request, $handler);

        if (! $response instanceof UnformattedResponse) {
            return $response;
        }

        $contentType = $this->extractContentType($response->getHeaderLine('Content-Type'));
        $formatter   = $this->formatters[$contentType] ?? null;

        return $this->formatResponse($response, $formatter);
    }
309267
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        try {
            return $this->route($request, $handler);
        } catch (BadRequestException $e) {
            if ($this->http400Handler !== null) {
                return $this->http400Handler->badRequest($e, $request);
            } else {
                throw $e;
            }
        } catch (PageNotFoundException $e) {
            return $handler->handle($request);
        }
    }
1022988
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $routeResult = $request->getAttribute(RouteResult::class);

        // if the routing is a success, return the response generated by the founded route handler.
        if ($routeResult && $routeResult->isSuccess()) {
            // add all the route middlewares (from the Route + RouteGroup).
            $this->pipeline->pipe($routeResult->getMatchedRouteMiddlewareStack());
            // add actual RouteResult (it's a RequestHandlerInterface) at the end of stack to generate the response.
            // It will execute the route callable using the paremeters from the request uri + default parameters values.
            $this->pipeline->pipe($routeResult);

            return $this->pipeline->handle($request);
        }

        // else, return the default response (it's an HTTP 204 empty body response).
        return $handler->handle($request);
    }
402352
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = Debugger::start($request);
        if ($response !== null) {
            return $response;
        }

        \ob_start();

        try {
            $response = $handler->handle($request);

            if ($this->isError($response->getStatusCode())) {
                throw new HttpErrorException(
                    $response->getReasonPhrase(),
                    $response->getStatusCode()
                );
            }

            return Debugger::writeToResponse($response);
        } catch (\Throwable $exception) {
            return Debugger::exceptionToResponse($exception);
        }
    }
850603
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $request = $request->withAttribute(
            'viewData',
            $this->merge($request, ['flashMessages' => $this->flashMessages])
        );
        return $handler->handle($request);
    }
648332
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
    {
        $this->startTransaction();
        $response = $handler->handle($request);
        $this->endTransaction();

        return $response;
    }