Builds a response to an incoming request by routing
it through the application.

@param Request $req

@return Response
540191
public function handleRequest(Request $req)
    {
        // set host name from request if not already set
        $config = $this['config'];
        if (!$config->get('app.hostname')) {
            $config->set('app.hostname', $req->host());
        }

        $res = new Response();
        try {
            // determine route by dispatching to router
            $routeInfo = $this['router']->dispatch($req->method(), $req->path());
            $this['routeInfo'] = $routeInfo;

            // set any route arguments on the request
            if (isset($routeInfo[2])) {
                $req->setParams($routeInfo[2]);
            }

            // the dispatch middleware is the final step
            $dispatch = new DispatchMiddleware();
            $dispatch->setApp($this);
            $this->middleware($dispatch);

            // the request is handled by returning the response
            // generated by the middleware chain
            return $this->runMiddleware($req, $res);
        } catch (\Exception $e) {
            return $this['exception_handler']($req, $res, $e);
        } catch (\Error $e) {
            return $this['php_error_handler']($req, $res, $e);
        }
    }
429337
protected function buildResponse()
    {
        $this->curl->persist();
        $response = $this->curl->exec();
        $info = $this->curl->getInfo();
        $errors = [
            'text' => $this->curl->error(),
            'code' => $this->curl->errno()
        ];

        try {
            return new Response(new ResponseBuilder($response, $info, $errors), new Filesystem());
        } catch (ResponseBuilderException $e) {
            throw new RequestException($e->getMessage(), $e->getCode());
        }
    }
965849
public function indexDataAction(Request $request)
        {

            $aRemoteApps = RemoteAppQuery::create()->find();
            $sResult     = $this->renderView('SlashworksAppBundle:RemoteApp:data.json.twig', array(
                'entities' => $aRemoteApps,
            ));

            $response = new Response($sResult);
            $response->headers->set('Content-Type', 'application/json');

            return $response;

        }
1268382
protected function buildResponse()
    {
        $response = new Response();
        if ($this->viewCache === true) {
            $response->setPublic();

            if ($this->ttlCache === true) {
                $response->setSharedMaxAge(
                    $this->defaultTtl
                );
            }

            // Make the response vary against Cookie header ensures that an HTTP
            // reverse proxy caches the different possible variations of the
            // response as it can depend on user role for instance. X-User-Hash cannot
            // be used since the website toolbar can have Owner( Self ) Policy Limitation.
            $response->setVary('Cookie');
        }

        return $response;
    }
1340999
public function indexAction(Request $request)
    {
        // Special case, not correctly setup yet. Do so now.
        if (!$this->isInstalled()) {
            return new RedirectResponse($request->getUri() . 'install.html');
        }

        return new Response(
            str_replace(
                'var TENSIDEApi=window.location.href.split(\'#\')[0];',
                'var TENSIDEApi=\'' . $request->getSchemeAndHttpHost() . $request->getBaseUrl() . '/\';',
                file_get_contents($this->getAssetsDir() . '/index.html')
            ),
            200,
            [
                'Content-Type' => 'text/html; charset=UTF-8'
            ]
        );
    }
123997
public function handle(Request $request): Response
    {
        try {
            $matcher = $this->getUrlMatcher($request);

            $parameters = $matcher->match($request->getPathInfo());

            if (empty($parameters['_controller'])) {
                throw new InvalidRouteException('Route requires a _controller callable');
            }

            if (!\is_callable($parameters['_controller'])) {
                throw new InvalidRouteException('_controller must be a callable');
            }

            $callback = $parameters['_controller'];

            $result = call_user_func_array($callback, $this->getControllerParameters($request, $parameters));

            if (!$result instanceof Response) {
                throw new InvalidResponseException('Response must be an instance of \Symfony\Component\HttpFoundation\Response');
            }
        } catch (\Exception $e) {
            $result = $this->handleException($request, $e);
        }

        return $result;
    }
1349217
public function handle(Request $request) : Response
    {
        try {
            return (new Pipeline)
                ->send($request)
                ->through($this->convertMiddlewareToPipelineStages($this->getMiddleware()), 'handle')
                ->then(function ($request) {
                    return $this->router->route($request);
                })
                ->execute();
        } catch (Exception $ex) {
            $this->setExceptionRendererVars($request);
            $this->exceptionHandler->handle($ex);

            return $this->exceptionRenderer->getResponse();
        } catch (Throwable $ex) {
            $this->setExceptionRendererVars($request);
            $this->exceptionHandler->handle($ex);

            return $this->exceptionRenderer->getResponse();
        }
    }
794242
public function send(Request $request)
    {
        $response  = new ListKeysResponse();
        $rpbGetReq = $this->createRpbMessage($request);
        $socket    = $this->client->emit($rpbGetReq, RiakMessageCodes::LIST_KEYS_REQ);
        $iterator  = new ProtoStreamIterator($this->client, $socket, RiakMessageCodes::LIST_KEYS_RESP);

        $response->iterator = new ProtoListKeysResponseIterator($iterator);

        return $response;
    }
437483
public function onRequest($req, $res)
    {
        $this->app->event->trigger('swoole.request');

        $this->resetOnRequest();

        /** @var Sandbox $sandbox */
        $sandbox = $this->app->make(Sandbox::class);
        $request = $this->prepareRequest($req);

        try {
            $sandbox->setRequest($request);

            $sandbox->init();

            $response = $sandbox->run($request);

            $this->sendResponse($sandbox, $response, $res);
        } catch (Throwable $e) {
            try {
                $exceptionResponse = $this->app
                    ->make(Handle::class)
                    ->render($request, $e);

                $this->sendResponse($sandbox, $exceptionResponse, $res);
            } catch (Throwable $e) {
                $this->logServerError($e);
            }
        } finally {
            $sandbox->clear();
        }
    }
479122
public function buildAction(Request $request)
    {
        $form = $this->getArchiveFormFactory()->createBuildForm()->handleRequest($request);

        if (!$form->isValid()) {
            $messages = [];

            /** @var \Symfony\Component\Form\FormError $error */
            foreach ($form->getErrors(true) as $error) {
                $messages[] = $error->getMessage();
            }

            $url = $request->headers->get('referer');

            if ($request->isXmlHttpRequest()) {
                return new AjaxResponse('', false, implode(' ', $messages), [], $url);
            }
            foreach ($messages as $message) {
                $this->getFlashNotifier()->error($message);
            }

            return $this->redirect($url);
        }

        set_time_limit(0);

        $filename = $this->getArchiver()->archive();

        $message = $this->getTranslator()->trans('archive.action.build.success', [], 'darvin_image');
        $url = $this->generateUrl('darvin_image_archive_download', [
            'filename' => $filename,
        ]);

        if ($request->isXmlHttpRequest()) {
            return new AjaxResponse('', true, $message, [], $url);
        }

        $this->getFlashNotifier()->success($message);

        return $this->redirect($url);
    }
879579
public function execute(Request $request) : Response
    {
        $host = $request->getHost();
        $socket = new ClientSocket($host, 80);
        $socket->connect();
        $communicator = $socket->getCommunicator();
        $communicator->write($request);
        $communicator->writeLine('');$communicator->writeLine('');
        
        $headers = new Headers();
        $body = ''; 
        
        $headerLine = true;

        $statusLine = $communicator->read(1024, PHP_NORMAL_READ);
        while($line = $communicator->read(5000, PHP_NORMAL_READ)){

            if ($headerLine && $line === PHP_EOL) {
                continue;
            }

            if ($headerLine && ($line === "\r" || $line === PHP_EOL)) {
                $headerLine = false;
                continue;
            }

            if ($headerLine) {
                $headers->add(Header::createFromString($line));
            }else{
                $body .= $line;
            }

        }

        return new Response($body, 200, $headers);
    }
861091
public function send(Request $request)
    {
        $response   = new GetSchemaResponse();
        $rpbGetReq  = $this->createRpbMessage($request);
        $rpbGetResp = $this->client->send($rpbGetReq, RiakMessageCodes::YOKOZUNA_SCHEMA_GET_REQ, RiakMessageCodes::YOKOZUNA_SCHEMA_GET_RESP);

        if ( ! $rpbGetResp instanceof RpbYokozunaSchemaGetResp) {
            return $response;
        }

        if ( ! $rpbGetResp->hasSchema()) {
            return $response;
        }

        $response->name    = $rpbGetResp->schema->name;
        $response->content = $rpbGetResp->schema->content;

        return $response;
    }
770582
public function send(Request $request)
    {
        $response = new SearchResponse();
        $rpbReq   = $this->createRpbMessage($request);
        $rpbResp  = $this->client->send($rpbReq, RiakMessageCodes::SEARCH_QUERY_REQ, RiakMessageCodes::SEARCH_QUERY_RESP);

        if ( ! $rpbResp instanceof RpbSearchQueryResp) {
            return $response;
        }

        $response->numFound = $rpbResp->num_found;
        $response->maxScore = $rpbResp->max_score;

        if ( ! $rpbResp->hasDocs()) {
            return $response;
        }

        $response->docs = array_map([$this, 'docToArray'], $rpbResp->docs);

        return $response;
    }
874128
protected function doRequest(Request $request)
    {

        $this->client->send($request, $response = new Response());

        return $response;
    }
972707
public function doRequestInProcess($request)
    {
        if ($this->mockedResponse) {
            $response = $this->mockedResponse;
            $this->mockedResponse = null;
            return $response;
        }

        $requestCookie = $request->getCookies();
        $requestServer = $request->getServer();
        $requestFiles = $this->remapFiles($request->getFiles());

        $parseResult = parse_url($request->getUri());
        $uri = $parseResult["path"];
        if (array_key_exists("query", $parseResult)) {
            $uri .= "?" . $parseResult["query"];
        }

        $requestRequestArray = $this->remapRequestParameters($request->getParameters());

        $requestServer['REQUEST_METHOD'] = strtoupper($request->getMethod());
        $requestServer['REQUEST_URI'] = $uri;
        $requestServer['HTTP_HOST'] = $this->domain;
        $requestServer['SERVER_PROTOCOL'] = 'HTTP/1.1';
        $requestServer['SERVER_NAME'] = $this->domain;
        $requestServer['HTTP_CLIENT_IP'] = '127.0.0.1';

        $this->index = $this->uriToIndexMapper->getIndexForUri($uri);

        $phpSelf = str_replace($this->rootFolder, '', $this->index);
        $requestServer['PHP_SELF'] = $phpSelf;

        $env = [
            'headers' => $this->headers,
            'cookie' => $requestCookie,
            'server' => $requestServer,
            'files' => $requestFiles,
            'request' => $requestRequestArray,
        ];

        if (strtoupper($request->getMethod()) == 'GET') {
            $env['get'] = $env['request'];
        } else {
            $env['post'] = $env['request'];
        }

        $requestScript = dirname(dirname(__DIR__)) . '/scripts/request.php';

        $command = PHP_BINARY .
            ' ' . escapeshellarg($requestScript) .
            ' ' . escapeshellarg($this->index) .
            ' ' . escapeshellarg(base64_encode(serialize($env)));

        $process = new Process($command);
        $process->run();
        $rawProcessOutput = $process->getOutput();

        $unserializedResponse = @unserialize(base64_decode($rawProcessOutput));

        if (false === $unserializedResponse) {
            $message = 'Server responded with: ' . $rawProcessOutput;
            throw new ModuleException(\Codeception\Module\WordPress::class, $message);
        }

        $_SERVER = empty($unserializedResponse['server']) ? [] : $unserializedResponse['server'];
        $_FILES = empty($unserializedResponse['files']) ? [] : $unserializedResponse['files'];
        $_REQUEST = empty($unserializedResponse['request']) ? [] : $unserializedResponse['request'];
        $_GET = empty($unserializedResponse['get']) ? [] : $unserializedResponse['get'];
        $_POST = empty($unserializedResponse['post']) ? [] : $unserializedResponse['post'];

        $content = $unserializedResponse['content'];
        $headers = $this->replaceSiteUrlDeep($unserializedResponse['headers'], $this->url);

        $response = new Response($content, $unserializedResponse['status'], $headers);

        return $response;
    }
673846
protected function sendRequestThroughRouter(Request $request)
    {
        return (new Pipeline($this->app))->send($request)->then(function ($request) {

            /**
             * @var Response $response
             */
            $response = $this->router->dispatch($request);

            if (property_exists($response, 'exception') && $response->exception instanceof Exception) {
                throw $response->exception;
            }

            return $response;
        });
    }
324267
public function run(Request $request) {
		$page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
		$page->setTitle($this->getServiceContainer()->getTranslator()->trans('profile'));

		$payload = new Blank();
		if ($request->isMethod('POST')) {
			$post = $request->request;
			$user = $this->getServiceContainer()->getAuthManager()->getUser();
			$domain = new UserDomain($this->getServiceContainer());
			$serializer = User::getSerializer();

			$fields = $serializer->getFields();
			$fields[] = 'display_name_user_select';
			$attribs = [];

			foreach ($fields as $field) {
				if ($post->has($field)) {
					$attribs[$field] = $post->get($field);
				}
			}

			$payload = $domain->update($user->getId(), ['attributes' => $attribs]);
		}
		return $this->responder->run($request, $payload);
	}