Execute the endpoint.

@param  RequestInterface  $request  A PSR-7 compatible Request instance.
@param  ResponseInterface $response A PSR-7 compatible Response instance.
@return ResponseInterface
507482
public function run(RequestInterface $request, ResponseInterface $response)
    {
        $previousId    = $request->getParam('widget_id');
        $widgetType    = $request->getParam('widget_type');
        $widgetOptions = $request->getParam('widget_options');
        $withData      = $request->getParam('with_data');

        if ($previousId) {
            $failMessage = $this->translator()->translation('Failed to reload widget');
        } else {
            $failMessage = $this->translator()->translation('Failed to load widget');
        }
        $errorThrown = strtr($this->translator()->translation('{{ errorMessage }}: {{ errorThrown }}'), [
            '{{ errorMessage }}' => $failMessage
        ]);
        $reqMessage  = $this->translator()->translation(
            '{{ parameter }} required, must be a {{ expectedType }}, received {{ actualType }}'
        );
        $typeMessage = $this->translator()->translation(
            '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}'
        );

        try {
            if (!$widgetType) {
                $actualType = is_object($widgetType) ? get_class($widgetType) : gettype($widgetType);
                $this->addFeedback('error', strtr($reqMessage, [
                    '{{ parameter }}'    => '"obj_type"',
                    '{{ expectedType }}' => 'string',
                    '{{ actualType }}'   => $actualType,
                ]));
                $this->setSuccess(false);

                return $response->withStatus(400);
            }

            $widget = $this->widgetFactory()->create($widgetType);
            $widget->setView($this->widgetView());

            if (isset($widgetOptions)) {
                if (!is_array($widgetOptions)) {
                    $actualType = is_object($widgetOptions) ? get_class($widgetOptions) : gettype($widgetOptions);
                    $this->addFeedback('error', strtr($typeMessage, [
                        '{{ parameter }}'    => '"widget_options"',
                        '{{ expectedType }}' => 'array',
                        '{{ actualType }}'   => $actualType,
                    ]));
                    $this->setSuccess(false);

                    return $response->withStatus(400);
                }

                if (!isset($widgetOptions['type'])) {
                    $widgetOptions['type'] = $widgetType;
                }

                $widget->setData($widgetOptions);
            }


            $widgetHtml = $widget->renderTemplate($widget->template());
            $jsRequirements = $widget->renderTemplate('{{&jsRequirements}}');
            $js = $widget->renderTemplate('{{&js}}');
            $widgetId   = $widget->widgetId();

            $this->setWidgetHtml($jsRequirements.$widgetHtml.$js);
            $this->setWidgetId($widgetId);

            if ($withData) {
                $widgetData = $widget->widgetDataForJs();
                $this->setWidgetData($widgetData);
            }

            if ($previousId) {
                $doneMessage = $this->translator()->translation('Widget Reloaded');
            } else {
                $doneMessage = $this->translator()->translation('Widget Loaded');
            }
            $this->addFeedback('success', $doneMessage);
            $this->setSuccess(true);

            return $response;
        } catch (Exception $e) {
            $this->addFeedback('error', strtr($errorThrown, [
                '{{ errorThrown }}' => $e->getMessage()
            ]));
            $this->setSuccess(false);

            return $response->withStatus(500);
        }
    }
974264
public function httpGet(RequestInterface $request, ResponseInterface $response)
    {
        // We're not using straight-up $_GET, because we want everything to be
        // unit testable.
        $getVars = $request->getQueryParameters();

        // CSP headers
        $response->setHeader('Content-Security-Policy', "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';");

        $sabreAction = isset($getVars['sabreAction']) ? $getVars['sabreAction'] : null;

        switch ($sabreAction) {
            case 'asset':
                // Asset handling, such as images
                $this->serveAsset(isset($getVars['assetName']) ? $getVars['assetName'] : null);

                return false;
            default:
            case 'info':
                try {
                    $this->server->tree->getNodeForPath($request->getPath());
                } catch (DAV\Exception\NotFound $e) {
                    // We're simply stopping when the file isn't found to not interfere
                    // with other plugins.
                    return;
                }

                $response->setStatus(200);
                $response->setHeader('Content-Type', 'text/html; charset=utf-8');

                $response->setBody(
                    $this->generateDirectoryIndex($request->getPath())
                );

                return false;

            case 'plugins':
                $response->setStatus(200);
                $response->setHeader('Content-Type', 'text/html; charset=utf-8');

                $response->setBody(
                    $this->generatePluginListing()
                );

                return false;
        }
    }
342431
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if ($this->cors->onlyPreflight()) {
            if ($this->cors->isPreflightRequest('psr-7', $request)) {
                if (!(($response = $this->getResponse()) instanceof ResponseInterface)) {
                    $response = $handler->handle($request);
                }

                return $this
                    ->handle($request, $response)
                    ->withStatus(204);
            }

            return $handler->handle($request);
        }

        return $this->handle($request, $handler->handle($request));
    }
416928
public function httpGet(RequestInterface $request, ResponseInterface $response)
    {
        $node = $this->server->tree->getNodeForPath($request->getPath());
        if ($node instanceof DAV\IFile) {
            return;
        }

        $subRequest = clone $request;
        $subRequest->setMethod('PROPFIND');

        $this->server->invokeMethod($subRequest, $response);

        return false;
    }
330094
public function delete( ServerRequestInterface $request, ResponseInterface $response )
	{
		return $this->client->delete( $request, $response );
	}
801059
public function response(ServerRequestInterface $request, ResponseInterface $response)
    {
        // Demo contents
        $contents = 'It works!';

        // Write Response to Body
        $response->getBody()->write($contents);

        // PSR-7 response
        return $response;
    }
531609
public static function factory(RequestInterface $request, Response $response)
    {
        if ($response->isClientError()) {
            $label = 'Client error response';
            $class = __NAMESPACE__ . '\\ClientErrorResponseException';
        } elseif ($response->isServerError()) {
            $label = 'Server error response';
            $class = __NAMESPACE__ . '\\ServerErrorResponseException';
        } else {
            $label = 'Unsuccessful response';
            $class = __CLASS__;
        }

        $message = $label . PHP_EOL . implode(PHP_EOL, array(
            '[status code] ' . $response->getStatusCode(),
            '[reason phrase] ' . $response->getReasonPhrase(),
            '[url] ' . $request->getUrl(),
        ));

        $e = new $class($message);
        $e->setResponse($response);
        $e->setRequest($request);

        return $e;
    }
259623
public function handle(RequestInterface $request): RequestInterface
    {
        return
            $request->withHeader(
                'Authorization',
                sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
            );
    }
938623
public function send(RequestInterface $request, ResponseInterface $response)
    {
        $procedure = $this->procedureLoader->load($this->procedure);

        $this->procedureCompiler->compile($procedure, $request);

        $procedure->run($request, $response);

        return $response;
    }
128866
private function handleRequest(RequestInterface $request, ResponseInterface $response): void
    {
        foreach ($this->routes as $route) {
            $routeMatch = $route->matches($request);

            if ($routeMatch === null) {
                continue;
            }

            $controllerClass = $routeMatch->getControllerClassName();
            $controller = new $controllerClass();

            /** @var ControllerInterface $controller */
            $controller->processRequest($this, $request, $response, $routeMatch->getAction(), $routeMatch->getParameters());

            return;
        }

        $response->setStatusCode(new StatusCode(StatusCode::NOT_FOUND));
    }
706818
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = new \GuzzleHttp\Psr7\Response();
        $controller = $this->getController(
            new \phpGone\Router\Routeur(),
            $request
        );
        if (is_null($controller)) {
            return $handler->handle($request);
        }
        ob_start();
        $controller->execute();
        $responseController = ob_get_clean();
        $response->getBody()->write($responseController);
        return $response;
    }
276241
public function responseToResultTransformer(ResponseInterface $response, RequestInterface $request)
    {
        $data = json_decode($response->getBody(), true);

        return new Result($data);
    }
279601
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE);

        /* @var \Swoft\Rpc\Server\Router\HandlerAdapter $handlerAdapter */
        $handlerAdapter = App::getBean('serviceHandlerAdapter');
        $response       = $handlerAdapter->doHandler($request, $serviceHandler);

        return $response;
    }
1044984
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $file = !empty($route->file) ? ltrim($route->file, '/') : '';

        if ($file[0] === '~' || strpos($file, '..') !== false) {
            trigger_error("Won't route to '$file': '~', '..' are not allowed in filename", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        if (!file_exists($file)) {
            trigger_error("Failed to route using '$file': File doesn't exist", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        $result = $this->includeScript($file, $request, $response);

        return $result === true || $result === 1 ? $response : $result;
    }
202874
protected function process(RequestInterface $request, string $responseClassName = null): ?ResponseInterface
    {
        $context = SerializationContext::create();

        $request = $this->serializer->serialize($request, $this->serializerFormat, $context);

        $response = $this->httpClient->post('', ['body' => $request]);

        if (!$responseClassName) {
            return null;
        }

        return $this->serializer->deserialize($response->getBody(), $responseClassName, $this->deserializerFormat);
    }
1001770
public function httpGet(RequestInterface $request, ResponseInterface $response)
    {
        $path = $request->getPath();

        try {
            $node = $this->server->tree->getNodeForPath($path);
        } catch (DAV\Exception\NotFound $e) {
            return;
        }

        if (!$node instanceof INode) {
            return;
        }

        $writer = $this->server->xml->getWriter();
        $writer->contextUri = $this->server->getBaseUri();
        $writer->openMemory();
        $writer->startDocument('1.0', 'UTF-8');
        $writer->startElement('{http://calendarserver.org/ns/}notification');
        $node->getNotificationType()->xmlSerializeFull($writer);
        $writer->endElement();

        $response->setHeader('Content-Type', 'application/xml');
        $response->setHeader('ETag', $node->getETag());
        $response->setStatus(200);
        $response->setBody($writer->outputMemory());

        // Return false to break the event chain.
        return false;
    }
316197
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');
        $callback = !empty($route->fn) ? $route->fn : null;

        if (!is_callable($callback)) {
            trigger_error("'fn' property of route shoud be a callable", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        return $callback($request, $response);
    }