Провести аунтификацию в соостветствии с типом сервиса

@param  \Psr\Http\Message\RequestInterface $request

@return \Psr\Http\Message\RequestInterface
175100
protected function authentication(RequestInterface $request)
	{
		if ($this->tokenRequired)
		{
			return $request->withHeader('Authorization', sprintf('OAuth %s', $this->getAccessToken()));
		}

		return $request;
	}
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;
	}
245600
private function doSearch(RequestInterface $request)
    {
        $searchRequest = [
            'index' => $request->getIndex(),
            'type'  => $request->getType(),
            'body'  => $this->requestMapper->buildSearchRequest($request),
        ];

        return $this->client->search($searchRequest);
    }
1175036
protected function setDataFromRequest(RequestInterface $request)
    {
        $keys = $this->validDataFromRequest();
        $data = $request->getParams($keys);
        $this->mergeData($data);

        return $this;
    }
1006845
public function getParsedResponse(RequestInterface $request)
    {
        try {
            $response = $this->getResponse($request);
        } catch (BadResponseException $e) {
            $response = $e->getResponse();
        }

        $parsed = $this->parseResponse($response);

        $this->checkResponse($response, $parsed);

        return $parsed;
    }
1190909
public function execute(RequestInterface $request): RequestInterface
    {
        $body = $request->getBody()->getContents();

        $iv = random_bytes(self::INITIATION_VECTOR_LENGTH);
        $aesKey = random_bytes(self::AES_KEY_LENGTH);
        $encryptedAesKey = $this->publicKey->encrypt($aesKey);
        $bodyEncrypted = $this->determineBodyStringEncrypted($body, $aesKey, $iv);
        $hmac = $this->determineHmac($aesKey, $iv, $bodyEncrypted);
        $encryptedHeaders = [
            self::HEADER_CLIENT_ENCRYPTION_IV => [base64_encode($iv)],
            self::HEADER_CLIENT_ENCRYPTION_KEY => [base64_encode($encryptedAesKey)],
            self::HEADER_CLIENT_ENCRYPTION_HMAC => [base64_encode($hmac)],
        ];

        return new Request(
            $request->getMethod(),
            $request->getUri(),
            array_merge($request->getHeaders(), $encryptedHeaders),
            $bodyEncrypted
        );
    }
69287
private function appendHeaders(RequestInterface $request)
    {
        $headers = $this->auth->getHeaders();
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }
        return $request;
    }
29793
public function handle(RequestInterface $request)
    {
        $handler = new RoutingHandler($this->container);

        if (! $this->has(Application::MIDDLEWARE))
        {
            return $handler->handle($request);
        }

        $dispatcher = $this->get(Application::MIDDLEWARE);

        return $dispatcher->process($request, $handler);
    }
1021944
public function setRequest(\Psr\Http\Message\RequestInterface $request) : \Psr\Http\Message\RequestInterface
    {
        return $this->request = $request;
    }
55721
public function execute(RequestInterface $request)
    {
        $httpRequest = $this->httpRequestBuilder->build($request);

        $httpResponse = $this->transport->execute($httpRequest);

        return $this->resultBuilderEngine->build($request, $httpResponse);
    }
676379
protected function setDataFromRequest(RequestInterface $request)
    {
        $keys = $this->validDataFromRequest();
        if (!empty($keys)) {
            $this->setData($request->getParams($keys));
        }

        return $this;
    }
680749
public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $promise = $this->sendAsyncRequest($request);

        return $promise->wait();
    }
311684
public function processRequest(RequestInterface $request)
    {
        $this->response = $this->communicator->getResponse($request);

        return $this->response;
    }
103573
public function renderIntoCookieHeader(RequestInterface $request) : RequestInterface
    {
        $cookieString = implode('; ', $this->cookies);

        $request = $request->withHeader(static::COOKIE_HEADER, $cookieString);

        return $request;
    }
387588
public function getRequest(RequestInterface $request)
    {
        $requestStr = $this->parser->getRequestAsString($request);
        $endpoint = (string)$request->getUri();
        $method = $request->getMethod();

        return [
            'request' => $requestStr,
            'endpoint' => $endpoint,
            'method' => $method,
        ];
    }
766272
final public function handle(RequestInterface $request)
    {
        $processed = $this->processing($request);

        if ($processed === null) {
            // the request has not been processed by this handler => see the next
            if ($this->successor !== null) {
                $processed = $this->successor->handle($request);
            }
        }

        return $processed;
    }
1359719
public function getRequest(): RequestInterface
    {
        if (!$this->request) {
            $this->resolveOptions();
            $this->request = $this->createRequest();
        }

        return parent::getRequest();
    }