@param RequestDescriptor $request
@param int $flags

@return bool|ResponseDescriptor

@throws ApiClientException
@throws TransportException
344477
public function send(RequestDescriptor $request, $flags = 0)
    {
        if (!empty($this->getAuthorization())) {
            $request->addHeader(self::OPTION_HEADER_AUTHORIZATION, $this->getAuthorization());
        }

        if ($this->delayNext || $this->isDelayed) {
            if (!$this->forceNext) {
                $this->delayedRequests[] = array($request, $flags | ApiRequestOption::NO_RESPONSE);

                // reset stackNext flag
                $this->delayNext = false;

                return true;
            } else {
                // reset forceNext flag
                $this->forceNext = false;
            }
        }

        $transport = $this->getAppropriateTransport($flags);

        if (is_null($transport)) {
            throw new ApiClientException(sprintf('No transport has been set on "%s"', get_class()));
        }

        try {
            $response = $transport->send($request, $flags);
        } catch (TransportException $e) {
            // fallback?
            if ($fallback = $this->getFallbackTransport()) {
                $response = $fallback->send($request, $flags);
            } else {
                throw $e;
            }
        }

        $this->resetFallbackTransport();

        return $response;
    }
329553
public function dispatch(Request $request)
    {
        $this->logger->debug('Dispatching request');
        try {
            /**
             * @var \Shade\Router\RouterInterface $router
             */
            $router = $this->serviceContainer->getService(ServiceContainer::SERVICE_ROUTER);
            $route = $router->route($request);
            if (!isset($this->primaryRequest)) {
                $this->primaryRequest = $request;
                $logMessage = 'Route found for primary request';
            } else {
                $logMessage = 'Route found for secondary request';
            }
            if (!isset($this->primaryRoute)) {
                $this->primaryRoute = $route;
            }
        } catch (Exception $e) {
            $this->logger->debug('Route not found');
            $response = new Response();
            $response->setCode(404);

            return $response;
        }

        $this->validateRoute($route);
        $this->logger->debug(
            $logMessage,
            [
                'controller' => $route->controller(),
                'action' => $route->action(),
                'args' => $route->args(),
            ]
        );
        $controllerClass = $route->controller();
        $actionName = $route->action();
        $actionArguments = $this->getMethodArguments($controllerClass, $actionName);

        if (method_exists($controllerClass, '__construct')) {
            $constructorArguments = $this->getMethodArguments($controllerClass, '__construct');
        }

        if (empty($constructorArguments)) {
            $controller = new $controllerClass();
        } else {
            $controllerReflection = new \ReflectionClass($controllerClass);
            $controller = $controllerReflection->newInstanceArgs($constructorArguments);
        }

        if (!($controller instanceof Controller)) {
            throw new Exception(
                "'{$controllerClass}' must inherit '\\Shade\\Controller'."
            );
        }

        /**
         * @var \Shade\Controller $controller
         */
        $controller->setControllerDispatcher($this);
        $controller->setView($this->serviceContainer->getService(ServiceContainer::SERVICE_VIEW));
        $controller->setCurrentRequest($request);
        $controller->setCurrentRoute($route);
        $controller->setPrimaryRequest($request);
        $controller->setPrimaryRoute($route);

        /**
         * @var Response $response
         */
        $response = call_user_func_array([$controller, $actionName], $actionArguments);
        if (!$response instanceof Response) {
            throw new Exception(
                "Executed controller hasn't returned instance of \\Shade\\Response. "
                .ucfirst(gettype($response)).' has been returned.'
            );
        }

        if (!$response->getCode()) {
            $response->setCode(200);
        }

        return $response;
    }
831071
public function call(string $method, $payload, int $flags = 0)
    {
        $this->relay->send(
            $method . pack("P", $this->seq),
            Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW
        );

        if ($flags & Relay::PAYLOAD_RAW) {
            $this->relay->send($payload, $flags);
        } else {
            $body = json_encode($payload);
            if ($body === false) {
                throw new Exceptions\ServiceException(sprintf(
                    "json encode: %s",
                    json_last_error_msg()
                ));
            }

            $this->relay->send($body);
        }

        $body = $this->relay->receiveSync($flags);

        if (!($flags & Relay::PAYLOAD_CONTROL)) {
            throw new Exceptions\TransportException("rpc response header is missing");
        }

        $rpc = unpack("Ps", substr($body, -8));
        $rpc['m'] = substr($body, 0, -8);

        if ($rpc["m"] != $method || $rpc["s"] != $this->seq) {
            throw new Exceptions\TransportException("rpc method call mismatch");
        }

        // request id++
        $this->seq++;

        // wait for the response
        $body = $this->relay->receiveSync($flags);

        return $this->handleBody($body, $flags);
    }
566551
public static function getResponder(Request $request)
    {
        if ($request instanceof HttpRequest) {
            return self::getHttpResponder($request);
        } else {
            $requestType = get_class($request);
            throw new \InvalidArgumentException("Requests of type '{$requestType}' are not supported.");
        }
    }
1363199
public function sendRequest(\TYPO3\Flow\Http\Request $request) {
		$responses = $this->sendRequests(array($request));
		if (isset($responses[0])) {
			return $responses[0];
		} else {
			return NULL;
		}
	}
1026462
protected function sendRequest(Request $request)
    {
        // Try to get the result.  Handle the possible exceptions that can arise
        try {
            $response = $this->client->send($request);

            $result       = new stdClass();
            $result->code = $response->getStatusCode();
            $result->body = json_decode($response->getBody(true));
        } catch (ClientErrorResponseException $e) {
            throw new ApiCallFailedException($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
        } catch (ServerErrorResponseException $e) {
            throw new ApiCallFailedException('Api call failed to complete due to a server error.', $e->getResponse()->getStatusCode(), $e);
        } catch (Exception $e) {
            throw new ApiCallFailedException($e->getMessage(), $e->getCode(), $e);
        }

        // If all worked out, return the result
        return $result;
    }
784117
private function filterRequest(Request $request)
    {
        $event = $this->eventDispatcher->raiseEvent(new FilterRequestEvent($request));
        if ($event->hasResponse()) {
            $rsp = $event->getResponse();
            if ($rsp instanceof Response) {
                $this->eventDispatcher->raiseEvent(new FilterResponseEvent($request, $rsp));

                return $rsp;
            } elseif ($rsp instanceof Request) {
                $this->guardAgainstInfiniteRedirection($request, $rsp);

                return $this->dispatch($rsp);
            }
        }

        //The event handlers did not return a Request or a Response so invoke the controller
        $response = $this->controllerDispatcher->runController($request);
        $this->eventDispatcher->raiseEvent(new FilterResponseEvent($request, $response));

        return $response;
    }
1343644
public function send(Request $request) {
        $method   = strtolower($request->getMethod());
        $response = $method === HttpMethods::GET || $method === HttpMethods::DELETE ? $this->restClient->$method($request->getUrlAndQuery(), $request->getCurlOptions()) : $this->restClient->$method($request->getUrlAndQuery(), $request->getPayload(), $request->getCurlOptions());

        try {
            return $request->isExpectedStatusCode($response->getStatusCode()) ? $response : Exceptions::RequestFailedException($request, $response->getStatusCode(), $response->getContent());
        } catch (DBALException\DriverException $e) {
            $responseExceptionFactory = new ResponseExceptionFactory();
            throw $responseExceptionFactory->createDbalException($response, $e);
        }
    }
1008938
public function send(Request $request)
    {
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $code         = $httpResponse->getStatusCode();
        $response     = new PutResponse();

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        $contentList = $this->getRiakContentList($httpResponse);
        $vClock      = $httpResponse->getHeader('X-Riak-Vclock');
        $key         = null;

        if ($httpResponse->hasHeader('Location')) {
            $location = $httpResponse->getHeader('Location');
            $key      = substr($location, strrpos($location, '/') + 1);
        }

        $response->key         = $key;
        $response->vClock      = $vClock;
        $response->contentList = $contentList;

        return $response;
    }
1199872
protected function doRequest($request)
    {
        // avoid shutting down the Kernel if no request has been performed yet
        // WebTestCase::createClient() boots the Kernel but do not handle a request
        if ($this->hasPerformedRequest && $this->reboot) {
            $this->kernel->shutdown();
        } else {
            $this->hasPerformedRequest = true;
        }

        if ($this->profiler) {
            $this->profiler = false;

            $this->kernel->boot();
            $this->kernel->getContainer()->get('profiler')->enable();
        }

        return parent::doRequest($request);
    }
893211
protected function bind($vars, ServerRequestInterface $request, array $parts)
    {
        $type = is_array($vars) && array_keys($vars) === array_keys(array_keys($vars)) ? 'numeric' : 'assoc';

        $values = $this->bindParts($vars, $type, $request, $parts);

        if ($vars instanceof Route) {
            $class = get_class($vars);
            $values = new $class($values);
        } elseif (is_object($vars) && $type === 'assoc') {
            $values = (object)$values;
        }
        
        return $values;
    }
255947
public function cgetAction(Request $request)
    {
        $fieldDescriptors = $this->getFieldDescriptors(DoctrineFieldDescriptorInterface::class);
        $factory = $this->get('sulu_core.doctrine_list_builder_factory');

        $listBuilder = $this->prepareListBuilder($fieldDescriptors, $request, $factory->create(Task::class));
        $result = $this->executeListBuilder($fieldDescriptors, $request, $listBuilder);

        for ($i = 0; $i < count($result); ++$i) {
            $result[$i] = $this->extendResponseItem($result[$i]);
        }

        return $this->handleView(
            $this->view(
                new ListRepresentation(
                    $result,
                    'tasks',
                    'get_tasks',
                    $request->query->all(),
                    $listBuilder->getCurrentPage(),
                    $listBuilder->getLimit(),
                    $listBuilder->count()
                )
            )
        );
    }
471036
private function executeListBuilder(array $fieldDescriptors, Request $request, ListBuilderInterface $listBuilder)
    {
        if (null === ($idsParameter = $request->get('ids'))) {
            return $listBuilder->execute();
        }

        $ids = array_filter(explode(',', $request->get('ids')));
        $listBuilder->in($fieldDescriptors['id'], $ids);

        $sorted = [];
        foreach ($listBuilder->execute() as $item) {
            $sorted[array_search($item['id'], $ids)] = $item;
        }

        ksort($sorted);

        return array_values($sorted);
    }
1093232
protected static function checkServerPort(Request $request): bool
    {
        return $request->server->has('SERVER_PORT') && self::HTTPS === (int)$request->server->get('SERVER_PORT');
    }
908289
public function find(Request $request, array $routes)
    {
        foreach ($routes as $route) {

            if(!$this->matchMethod($request, $route)){
                continue;
            }

            if(!$this->matchContentType($request, $route)){
                continue;
            }

            if(!$this->matchFilters($route)){
                continue;
            }

            $routeMatches = $this->matchPattern($request, $route);
            if ($routeMatches) {
                $route->setMatches($routeMatches);
                return $route;
            }
        }
        throw new RouteException(
            sprintf('No route found for uri "%s"', $request->getRequestUri()),
            $request,
            $routes
        );
    }
771808
public static function register(string $protocol, string $root = null, int $flags = 0): bool
    {
        $wrappers = stream_get_wrappers();
        if (in_array($protocol, $wrappers)) {
            throw new Exception(
                "Protocol '$protocol' has been already registered"
            );
        }
        $wrapper = stream_wrapper_register($protocol, get_called_class(), $flags);

        if ($wrapper) {
            if (null !== $root) {
                $content = Entity::newInstance($root);
            } else {
                $content = null;
            }

            $partition = new Partition($content);

            self::$partitions[$protocol] = $partition;
        }

        return $wrapper;
    }
187673
protected function post(RequestDescriptor $descriptor)
    {
        if (!array_key_exists('Content-Type', $descriptor->getHeaders()) && !empty($descriptor->getBodyParams())) {
            $descriptor->addHeader('Content-Type', 'application/x-www-form-urlencoded');
        }
        
        $request = new Request(
            $descriptor->getMethod(),
            $descriptor->getUrl(),
            $descriptor->getHeaders(),
            $descriptor->fetchBody()
        );

        return $request;
    }