Create a curl handle for a request

@param RequestInterface $request Request

@return CurlHandle
512983
protected function createCurlHandle(RequestInterface $request)
    {
        $wrapper = CurlHandle::factory($request);
        $this->handles[$request] = $wrapper;
        $this->resourceHash[(int) $wrapper->getHandle()] = $request;

        return $wrapper;
    }
663536
public function execute(RequestInterface $request): RequestInterface
    {
        if (is_null($this->sessionToken)) {
            return $request;
        } else {
            return $request->withHeader(
                self::HEADER_CLIENT_AUTHENTICATION,
                [$this->sessionToken->getToken()]
            );
        }
    }
320176
protected function dispatchOnRequest(RequestInterface $request): RequestInterface
    {
        $requestEvent = new RequestEvent($request);
        $this->dispatcher->dispatch($this->requestEvent, $requestEvent);

        return $requestEvent->getRequest();
    }
233054
public function process(RequestInterface $request, RequestHandlerInterface $handler)
    {
        $response = $handler->handle($request);

        $response->body()->write('World!');

        return $response;
    }
668211
protected function createClientRequest(RequestInterface $request): PsrRequestInterface
    {
        $endpoint = $this->endpointService->getEndpointForRequest($request);

        return new Request(
            'POST',
            $endpoint->getRequestPath(),
            $this->getRequestHeaders($endpoint),
            $this->serializer->serialize($request, 'json')
        );
    }
1209489
public function route(RequestInterface $request)
	{
	    /** @var Request $request */
	    
	    // set errorHandler ContentType
	    Ioc::errorHandler()->setContentType($request->detectContentType());
	    
	    // use origin uri to parsed
	    $uri = $request->getUri();
	    $uriPath   = $uri->getPath();
	    $uriQuery  = $uri->getQuery();
	    
	    // omit query of path, if webserver `rewrite ^/(.*)$ /index.php?$1 last;`
	    if (strpos('/' . $uriQuery . '&', $uriPath . '&') === 0) {
	        $uri = $uri->withQuery(trim(str_replace($uriPath, '', '/' . $uriQuery), '&'));
	        $request = $request->withUri($uri);
	    }
	    
	    // queryParams
	    $queryParams = $request->getQueryParams();
	    $reUriPath  = trim($uriPath, '/'); 
	    $reUriPath2 = str_replace('.', '_', $reUriPath);
	    if (isset($_GET[$reUriPath2]) && !$_GET[$reUriPath2]) {
	        unset($queryParams[$reUriPath]);
	        unset($_GET[$reUriPath]);
	        unset($_GET[$reUriPath2]);
        }
        
	    if (!strpos($uriPath, '.php')) {
	        Config::set('router.url_mode', 1);
	    }
	    
	    // router parse and dispatch
	    $router    = $this->getRouter();
	    $result    = $router->dispatch($request->getMethod(), $uriPath);
	    
	    $this->setRoute($result->route);
	    
	    if ($result->flag == DispatchResult::FOUND) {
	        
	        $basePath = $this->getBasePath();
	        
	        // route and route arguments and route callable
	        $route = $result->route; 
	        $routeArguments = $route->getArguments();
	        $controller = static::getControllerFromArguments($routeArguments);
	        $callable = $route->getCallable();
	        
	        // if queryParams has r param: https://domain.cn/?r=/a/b/c
	        if (isset($queryParams['r'])) {
	            $controller = $queryParams['r'];
	            unset($queryParams['r']);
	        }
	        unset($routeArguments['controller']);
	        
	        // merge routeArguments and queryParams
	        $request = $request->withQueryParams(array_merge($routeArguments, $queryParams));
	        
	        if (is_callable($callable, false)) {         // 1. url => callbale, return it
	            $object = $callable;
	        } elseif (is_string($callable)) {
	            if (strpos($callable, 'http') === 0) {   // 2. url => https://xxx , return file_get_contents() from it
	                $object = function () use ($callable) {
	                    return file_get_contents($callable);
	                };
	            } elseif (strpos($callable, '.php') !== false) { // 3. url => ***.php, try [***.php, basePath/***.php, basePath/php/***.php]
	                $handleFile = false;
	                $files = [
	                    $callable,
	                    $basePath . trim($callable, '\/'),
	                    $basePath . 'php/'. trim($callable, '\/')
	                ];
	                foreach ($files as $file) {
	                    if (file_exists($file)) {
	                        $handleFile = $file;
	                        break;
	                    }
	                }
	                
	                if (!$handleFile) {
	                    throw new InvalidConfigException('page is not exists:' . $callable);
	                }
	                
	                $object = function () use ($handleFile) {
	                    return include $handleFile;
	                };
	            } else {     // 4. url => string|array, parse to controller
	                
	                if ($callable) {
	                    $callable = trim($callable, '\/');
	                    $parts = parse_url($callable);
	                    if (isset($parts['path'])) {
	                        if (!$controller) {
	                            $controller = $parts['path'];
	                        } else {
	                            $controller = $parts['path'] . '/' . trim($controller, '\/');
	                        }
	                    }
	                    
	                    if (isset($parts['query'])) {
	                        parse_str($parts['query'], $arr);
	                        foreach ($arr as $k=>$v) {
	                            $routeArguments[$k] = urlencode($v);
	                        }
	                        $request = $request->withQueryParams(array_merge($routeArguments, $queryParams));
	                    }
	                }
	                
	                $module = $this->getCurrentModule()->getName();
	                $controller = trim($controller, '/');
	                
	                // get controller: first current module, then app, then default module
	                if ($module) {
	                    // 这里controller是从原生uri解析的，在不使用二级域名时包含模块路径，将模块路径去掉
	                    if ($controller && strpos(Config::getRootUrl(), $uri->getHost()) === false) {
	                        $_wmodule  = '/' . $module . '/';
	                        $_wmodule2 = $this->getCurrentModule()->getAlias();
	                        $_wmodule2 = $_wmodule2 ? '/' . $_wmodule2 . '/' : '';
	                        if (strpos('/' . $controller . '/', $_wmodule) === 0) {
	                            $controller = substr_replace('/' . $controller . '/', '', 0, strlen($_wmodule));
	                        } elseif ($_wmodule2 && strpos('/' . $controller . '/', $_wmodule2) === 0) {
	                            $controller = substr_replace('/' . $controller . '/', '', 0, strlen($_wmodule2));
	                        }
	                        $controller = trim($controller, '/');
	                    }
	                    
	                    $object = $this->getCurrentModule()->getController($controller);
	                } else {
	                    $object = $this->getController($controller);
	                }
	                
	                if (!$object && !$this->isDefaultModule()) {
                        $object = $this->getDefaultModule()->getController($controller);
	                }
	                
	                if ($object && $object->getHandleStack($request)) {
	                    // set current module
	                    $this->currentModule = $object->getModule();
	                    
	                } else {
	                    $object = $this->get('notFoundHandler');
	                }
	            }
	        } else {
	            throw new InvalidConfigException('route is error:' . print_r($callable, true));
	        }
	    } elseif ($result->flag == DispatchResult::METHOD_NOT_ALLOWED) {
	        $request = $request->withAttributes('allowMethods', $result->info);
	        $object = $this->get('notAllowedHandler');
	    } else {
	        $object = $this->get('notFoundHandler');
	    }
	    
	    // reset request
	    $this->setRequest($request);
	    
	    if (!($object instanceof Controller)) {
	        $object = new \Wslim\Web\Controller($object);
	    }
	    
	    $oClassname = get_class($object->getHandler());
	    $errmsg = sprintf('[%s][%s]%s:%s', $request->getMethod(), UriHelper::getCurrentUrl(), $oClassname, $object->getCamelCaseAction());
	    Ioc::logger('router')->debug($errmsg);
	    
	    return $object;
	}
461109
public function execute(RequestInterface $request): RequestInterface
    {
        if ($request->getUri()->getPath() === self::ENDPOINT_INSTALLATION) {
            return $request;
        } else {
            $signature = $this->determineRequestSignature(
                $request->getUri(),
                $request->getMethod(),
                $request->getBody()->getContents(),
                $request->getHeaders()
            );

            return $request->withHeader(self::HEADER_CLIENT_SIGNATURE, $signature);
        }
    }
625214
public function sendRequest(RequestInterface $request):ResponseInterface{

		// get authorization only if we request the provider API
		if(strpos((string)$request->getUri(), $this->apiURL) === 0){
			$token = $this->storage->getAccessToken($this->serviceName);

			// attempt to refresh an expired token
			if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){
				$token = $this->refreshAccessToken($token);
			}

			$request = $this->getRequestAuthorization($request, $token);
		}

		return $this->http->sendRequest($request);
	}
105641
public function addAuthHeader(RequestInterface $request)
    {
        if (!empty($this->token['access_token'])) {
            return $request->withHeader(
                'Authorization',
                'Bearer ' . $this->token['access_token']
            );
        }

        return $request->withHeader(
            'Authorization',
            'Client-ID ' . $this->clientId
        );
    }
175100
protected function authentication(RequestInterface $request)
	{
		if ($this->tokenRequired)
		{
			return $request->withHeader('Authorization', sprintf('OAuth %s', $this->getAccessToken()));
		}

		return $request;
	}
642465
protected function handleRequest(RequestInterface $request): RequestInterface
    {
        if ($request instanceof JsonApiRequest) {
            $document = $request->getDocument();
            $stream   = $this->documentToStream($document);

            return $request->withBody($stream);
        }

        return $request;
    }
856165
public static function fromPsrRequest(RequestInterface $request) {
		if (!$request->hasHeader('C-AAUID') || !$request->hasHeader('C-Access-Token'))
			return null;

		$context = new AccountContext(
			new IRI('aauid:'.$request->getHeaderLine('C-AAUID')),
				$request->getHeaderLine('C-Access-Token'));

		$context->parsePsrRequest($request);

		return $context;
	}
1371067
public function request(RequestInterface $request)
    {
        $uri = $request->getUri()
            ->withPath('')
            ->withQuery('')
            ->withFragment('');

        $uri = $uri . $request->getRequestTarget();

        $request = $request->withRequestTarget($uri);

        return $this->doRequest($request);
    }
1371934
private function createRequest(RequestInterface $request)
    {
        $options = [
            'exceptions' => false,
            'allow_redirects' => false,
        ];

        $options['version'] = $request->getProtocolVersion();
        $options['headers'] = $request->getHeaders();
        $body = (string) $request->getBody();
        $options['body'] = '' === $body ? null : $body;

        return $this->client->createRequest(
            $request->getMethod(),
            (string) $request->getUri(),
            $options
        );
    }
208526
public function authorize(RequestInterface $request)
    {
        if (!$area = $this->findMatchingArea($request)) {
            return $this;
        }

        if (!$this->user) {
            throw new AuthorizationException(sprintf('Access denied to area "%s". No authenticated user', $area->pattern()));
        }

        if (!$area->authorize($this->user, $request->clientIp())) {
            throw new AuthorizationException(sprintf('Access denied to area "%s". Authenticated user does not have access', $area->pattern()));
        }

        return $this;
    }
1282571
public function handle(RequestInterface $request)
    {
        $index = 0;

        while ($this->canSetNextCore($index)) {
            $this->middlewares[$index]->setNextCore($this->middlewares[$index + 1]);
            ++$index;
        }

        return $this->middlewares[0]->handle($request);
    }
1021944
public function setRequest(\Psr\Http\Message\RequestInterface $request) : \Psr\Http\Message\RequestInterface
    {
        return $this->request = $request;
    }