|
|
private function assertStatusCodeIsInteger($statusCode) |
|
{ |
|
if (filter_var($statusCode, FILTER_VALIDATE_INT) === false) { |
|
throw new \InvalidArgumentException('Status code must be an integer value.'); |
|
} |
|
} |
|
|
|
private function assertStatusCodeRange($statusCode) |
$body = null, |
|
$version = '1.1', |
|
$reason = null |
|
) { |
|
$this->assertStatusCodeIsInteger($status); |
|
$status = (int) $status; |
|
$this->assertStatusCodeRange($status); |
|
|
|
$this->statusCode = $status; |
$startLine[1], |
|
$headers, |
|
$this->sink, |
|
substr($startLine[0], 5), |
|
isset($startLine[2]) ? (string) $startLine[2] : null |
|
); |
|
} |
|
|
|
public function __get($name) |
) { |
|
$value = trim($h); |
|
if ($value === '') { |
|
$startingResponse = true; |
|
$easy->createResponse(); |
|
if ($onHeaders !== null) { |
|
try { |
|
$onHeaders($easy->response); |
|
} catch (\Exception $e) { |
usleep($options['delay'] * 1000); |
|
} |
|
|
|
$easy = $this->factory->create($request, $options); |
|
curl_exec($easy->handle); |
|
$easy->errno = curl_errno($easy->handle); |
|
|
|
return CurlFactory::finish($this, $easy, $this->factory); |
|
} |
) { |
|
return function (RequestInterface $request, array $options) use ($default, $sync) { |
|
return empty($options[RequestOptions::SYNCHRONOUS]) |
|
? $default($request, $options) |
|
: $sync($request, $options); |
|
}; |
|
} |
|
|
|
/** |
callable $streaming |
|
) { |
|
return function (RequestInterface $request, array $options) use ($default, $streaming) { |
|
return empty($options['stream']) |
|
? $default($request, $options) |
|
: $streaming($request, $options); |
|
}; |
|
} |
|
} |
$fn = $this->nextHandler; |
|
|
|
// Don't do anything if the request has no body. |
|
if ($request->getBody()->getSize() === 0) { |
|
return $fn($request, $options); |
|
} |
|
|
|
$modify = []; |
|
|
{ |
|
return function (callable $handler) { |
|
return function ($request, array $options) use ($handler) { |
|
if (empty($options['cookies'])) { |
|
return $handler($request, $options); |
|
} elseif (!($options['cookies'] instanceof CookieJarInterface)) { |
|
throw new \InvalidArgumentException('cookies must be an instance of GuzzleHttp\Cookie\CookieJarInterface'); |
|
} |
|
$cookieJar = $options['cookies']; |
if (empty($options['allow_redirects']['max'])) { |
|
return $fn($request, $options); |
|
} |
|
|
|
return $fn($request, $options) |
|
->then(function (ResponseInterface $response) use ($request, $options) { |
|
return $this->checkRedirect($request, $options, $response); |
|
}); |
|
} |
return function ($request, array $options) use ($handler) { |
|
if (empty($options['http_errors'])) { |
|
return $handler($request, $options); |
|
} |
|
return $handler($request, $options)->then( |
|
function (ResponseInterface $response) use ($request) { |
|
$code = $response->getStatusCode(); |
|
if ($code < 400) { |
|
return $response; |
public function __invoke(RequestInterface $request, array $options) |
|
{ |
|
$handler = $this->resolve(); |
|
|
|
return $handler($request, $options); |
|
} |
|
|
|
/** |
|
* Dumps a string representation of the stack. |
/** @var HandlerStack $handler */ |
|
$handler = $options['handler']; |
|
|
|
try { |
|
return Promise\promise_for($handler($request, $options)); |
|
} catch (\Exception $e) { |
|
return Promise\rejection_for($e); |
|
} |
|
} |
$request = new Psr7\Request($method, $uri, $headers, $body, $version); |
|
// Remove the option so that they are not doubly-applied. |
|
unset($options['headers'], $options['body'], $options['version']); |
|
|
|
return $this->transfer($request, $options); |
|
} |
|
|
|
/** |
|
* Create and send an HTTP request. |
*/ |
|
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