// weak type check to also accept null until we can add scalar type hints |
|
if ($uri != '') { |
|
$parts = self::parse($uri); |
|
if ($parts === false) { |
|
throw new \InvalidArgumentException("Unable to parse URI: $uri"); |
|
} |
|
$this->applyParts($parts); |
|
} |
|
} |
array $protocols |
|
) { |
|
$location = Psr7\UriResolver::resolve( |
|
$request->getUri(), |
|
new Psr7\Uri($response->getHeaderLine('Location')) |
|
); |
|
|
|
// Ensure that the redirect URI is allowed based on the protocols. |
|
if (!in_array($location->getScheme(), $protocols)) { |
$modify['method'] = 'GET'; |
|
$modify['body'] = ''; |
|
} |
|
|
|
$uri = $this->redirectUri($request, $response, $protocols); |
|
if (isset($options['idn_conversion']) && ($options['idn_conversion'] !== false)) { |
|
$idnOptions = ($options['idn_conversion'] === true) ? IDNA_DEFAULT : $options['idn_conversion']; |
|
$uri = Utils::idnUriConvert($uri, $idnOptions); |
|
} |
return $response; |
|
} |
|
|
|
$this->guardMax($request, $options); |
|
$nextRequest = $this->modifyRequest($request, $options, $response); |
|
|
|
if (isset($options['allow_redirects']['on_redirect'])) { |
|
call_user_func( |
|
$options['allow_redirects']['on_redirect'], |
} |
|
|
|
return $fn($request, $options) |
|
->then(function (ResponseInterface $response) use ($request, $options) { |
|
return $this->checkRedirect($request, $options, $response); |
|
}); |
|
} |
|
|
|
/** |
$value = $this->value; |
|
$queue->add(static function () use ($p, $value, $onFulfilled) { |
|
if (Is::pending($p)) { |
|
try { |
|
$p->resolve($onFulfilled($value)); |
|
} catch (\Throwable $e) { |
|
$p->reject($e); |
|
} catch (\Exception $e) { |
|
$p->reject($e); |
public function run() |
|
{ |
|
while ($task = array_shift($this->queue)) { |
|
/** @var callable $task */ |
|
$task(); |
|
} |
|
} |
|
|
|
/** |
{ |
|
try { |
|
$wfn = $this->waitFn; |
|
$this->waitFn = null; |
|
$wfn(true); |
|
} catch (\Exception $reason) { |
|
if ($this->state === self::PENDING) { |
|
// The promise has not been resolved yet, so reject the promise |
|
// with the exception. |
{ |
|
if ($this->state !== self::PENDING) { |
|
return; |
|
} elseif ($this->waitFn) { |
|
$this->invokeWaitFn(); |
|
} elseif ($this->waitList) { |
|
$this->invokeWaitList(); |
|
} else { |
|
// If there's no wait function, then reject the promise. |
$this->waitList = null; |
|
|
|
foreach ($waitList as $result) { |
|
do { |
|
$result->waitIfPending(); |
|
$result = $result->result; |
|
} while ($result instanceof Promise); |
|
|
|
if ($result instanceof PromiseInterface) { |
return; |
|
} elseif ($this->waitFn) { |
|
$this->invokeWaitFn(); |
|
} elseif ($this->waitList) { |
|
$this->invokeWaitList(); |
|
} else { |
|
// If there's no wait function, then reject the promise. |
|
$this->reject('Cannot wait on a promise that has ' |
|
. 'no internal wait function. You must provide a wait ' |
} |
|
|
|
public function wait($unwrap = true) |
|
{ |
|
$this->waitIfPending(); |
|
|
|
if ($this->result instanceof PromiseInterface) { |
|
return $this->result->wait($unwrap); |
|
} |
*/ |
|
public function request($method, $uri = '', array $options = []) |
|
{ |
|
$options[RequestOptions::SYNCHRONOUS] = true; |
|
return $this->requestAsync($method, $uri, $options)->wait(); |
|
} |
|
|
|
/** |
|
* Get a client configuration option. |
$res = $client->request('get', $curl_arr, [ |
|
'timeout' => 8, |
|
'headers' => [ |
|
'User-Agent' => $http_user_agent, |
|
'content-type' => 'application/json; charset=UTF-8', |
|
//'Authorization'=>"Bearer ".$token, |
|
] |
|
//'body' => $body |
|
]); |
|
|
$show=array(); |
|
if (isset($url)) |
|
{ |
|
$r=$this->guzzlehttp($url); |
|
if ($r["code"]=="0") |
|
{ |
|
$content=$r["file"]; |
|
|
|
|
//$site_info["baidu_site"]=$siteinfo->get_search_num_action_baidu($url,$action="site");//百度收录 |
|
//$site_info["baidu_domain"]=$siteinfo->get_search_num_action_baidu($url,$action="domain");//百度反链 |
|
//$site_info["baidu_site_7days"]=$siteinfo->get_search_num_action_baidu($url,$action="site",$type="7days");//百度反链 |
|
$site_info["siteinfo"]=$this->getSiteInfo($url,0);//网站相关信息 |
|
$site_info["sogou_pr"]=$this->getsogoupr($url);//搜狗PR值 |
|
$site_info["alexa_rank"]=$this->getalexarank($url);//alexa 排名 |
|
$site_info["whois"]=$this->getwhois($url);//whois |
|
$site_info["pr"]=$this->getpr($url);//pr |
* @throws \UnexpectedValueException If return value of action is not `null` or `ResponseInterface` instance. |
|
*/ |
|
public function invokeAction(Closure $action, array $args): void |
|
{ |
|
$result = $action(...$args); |
|
if ($result !== null && !$result instanceof ResponseInterface) { |
|
throw new UnexpectedValueException(sprintf( |
|
'Controller actions can only return ResponseInterface instance or null. ' |
|
. 'Got %s instead.', |
$args = $this->getActionArgs( |
|
$action, |
|
array_values((array)$controller->getRequest()->getParam('pass')) |
|
); |
|
$controller->invokeAction($action, $args); |
|
|
|
$result = $controller->shutdownProcess(); |
|
if ($result instanceof ResponseInterface) { |
|
return $result; |
|
|
return $runner->run($middlewareQueue, $controller->getRequest(), $this); |
|
} |
|
|
|
return $this->handle($controller->getRequest()); |
|
} |
|
|
|
/** |
|
* Invoke the action. |
} |
|
|
|
$controller = $this->controllerFactory->create($request); |
|
|
|
return $this->controllerFactory->invoke($controller); |
|
} |
|
} |
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
|
} |
|
|
|
$response = new Response([ |
|
'body' => 'Middleware queue was exhausted without returning a response ' |
if ($method === 'GET' && $cookieData === null) { |
|
$token = $this->createToken(); |
|
$request = $request->withAttribute('csrfToken', $this->saltToken($token)); |
|
/** @var mixed $response */ |
|
$response = $handler->handle($request); |
|
|
|
return $this->_addTokenCookie($token, $request, $response); |
|
} |
|
|
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
{ |
|
$locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language')); |
|
if (!$locale) { |
|
return $handler->handle($request); |
|
} |
|
if ($this->locales !== ['*']) { |
|
$locale = Locale::lookup($this->locales, $locale, true); |
|
} |
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
*/ |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
{ |
|
if (!in_array($request->getMethod(), $this->methods, true)) { |
|
return $handler->handle($request); |
|
} |
|
[$type] = explode(';', $request->getHeaderLine('Content-Type')); |
|
$type = strtolower($type); |
|
if (!isset($this->parsers[$type])) { |
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
); |
|
} |
|
$matching = Router::getRouteCollection()->getMiddleware($middleware); |
|
if (!$matching) { |
|
return $handler->handle($request); |
|
} |
|
|
|
$middleware = new MiddlewareQueue($matching); |
|
$runner = new Runner(); |
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
{ |
|
$url = $request->getUri()->getPath(); |
|
if (strpos($url, '..') !== false || strpos($url, '.') === false) { |
|
return $handler->handle($request); |
|
} |
|
|
|
if (strpos($url, '/.') !== false) { |
|
return $handler->handle($request); |
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
*/ |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
{ |
|
try { |
|
return $handler->handle($request); |
|
} catch (RedirectException $exception) { |
|
return $this->handleRedirect($exception); |
|
} catch (Throwable $exception) { |
|
return $this->handleException($exception, $request); |
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
$this->queue = $queue; |
|
$this->queue->rewind(); |
|
$this->fallbackHandler = $fallbackHandler; |
|
|
|
return $this->handle($request); |
|
} |
|
|
|
/** |
|
* Handle incoming server request and return a response. |
} |
|
|
|
$this->dispatchEvent('Server.buildMiddleware', ['middleware' => $middleware]); |
|
|
|
$response = $this->runner->run($middleware, $request, $this->app); |
|
|
|
if ($request instanceof ServerRequest) { |
|
$request->getSession()->close(); |
|
} |
// Bind your application to the server. |
|
$server = new Server(new Application(dirname(__DIR__) . '/config')); |
|
|
|
// Run the request/response through the application and emit the response. |
|
$server->emit($server->run()); |
|
|
If you want to customize this error message, create templates/Error/error500.php