Success example

public function __construct(array &$dnsMap)
    {
        $this->dnsMap = &$dnsMap;
    }

    public function resolve(string $name, int $typeRestriction = null): Promise
    {
        if (!isset($this->dnsMap[$name]) || !\in_array($typeRestriction[Record::A, null], true)) {
            return Dns\resolver()->resolve($name$typeRestriction);
        }

        return new Success([new Record($this->dnsMap[$name], Record::A, null)]);
    }

    public function query(string $name, int $type): Promise
    {
        if (!isset($this->dnsMap[$name]) || Record::A !== $type) {
            return Dns\resolver()->query($name$type);
        }

        return new Success([new Record($this->dnsMap[$name], Record::A, null)]);
    }
}
$info['user_data'] = $options['user_data'];
        $info['max_duration'] = $options['max_duration'];
        $info['debug'] = '';

        $onProgress = $options['on_progress'] ?? static function D) {};
        $onProgress = $this->onProgress = static function D) use (&$info$onProgress) {
            $info['total_time'] = microtime(true) - $info['start_time'];
            $onProgress((int) $info['size_download']((int) (1 + $info['download_content_length']) ?: 1) - 1, (array) $info);
        };

        $pauseDeferred = new Deferred();
        $pause = new Success();

        $throttleWatcher = null;

        $this->id = $id = self::$nextId++;
        Loop::defer(static function D) use ($request$multi$id, &$info, &$headers$canceller, &$options$onProgress, &$handle$logger, &$pause) {
            return new Coroutine(self::generateResponse($request$multi$id$info$headers$canceller$options$onProgress$handle$logger$pause));
        });

        $info['pause_handler'] = static function Dfloat $duration) use (&$throttleWatcher, &$pauseDeferred, &$pause) {
            if (null !== $throttleWatcher) {
                Loop::cancel($throttleWatcher);
            }
if ($request->hasHeader('proxy-authorization')) {
            $request->removeHeader('proxy-authorization');
        }

        if ($options['capture_peer_cert_chain']) {
            $info['peer_certificate_chain'] = [];
        }

        $request->addEventListener(new AmpListener($info$options['peer_fingerprint']['pin-sha256'] ?? []$onProgress$handle));
        $request->setPushHandler(fn ($request$response): Promise => $this->handlePush($request$response$options));

        ($request->hasHeader('content-length') ? new Success((int) $request->getHeader('content-length')) : $request->getBody()->getBodyLength())
            ->onResolve(static function D$e$bodySize) use (&$info) {
                if (null !== $bodySize && 0 <= $bodySize) {
                    $info['upload_content_length'] = ((1 + $info['upload_content_length']) ?? 1) - 1 + $bodySize;
                }
            });

        [$client$connector] = $this->getClient($options);
        $response = $client->request($request$cancellation);
        $response->onResolve(static function D$e) use ($connector, &$handle) {
            if (null === $e) {
                $handle = $connector->handle;
            }
$this->info = &$info;
        $this->pinSha256 = $pinSha256;
        $this->onProgress = $onProgress;
        $this->handle = &$handle;
    }

    public function startRequest(Request $request): Promise
    {
        $this->info['start_time'] ??= microtime(true);
        ($this->onProgress)();

        return new Success();
    }

    public function startDnsResolution(Request $request): Promise
    {
        ($this->onProgress)();

        return new Success();
    }

    public function startConnectionCreation(Request $request): Promise
    {
        (
$this->offset = 0;
            } elseif ($this->body instanceof ResourceInputStream) {
                fseek($this->body->getResource()$this->offset);
            }
        }

        return $this;
    }

    public function getHeaders(): Promise
    {
        return new Success([]);
    }

    public function getBodyLength(): Promise
    {
        return new Success($this->length - $this->offset);
    }

    public function read(): Promise
    {
        $this->info['size_upload'] += $this->uploaded;
        $this->uploaded = 0;
        (
Home | Imprint | This part of the site doesn't use cookies.