Repository: symfony/symfony
File: src/Symfony/Component/HttpClient/AmpHttpClient.php (PHP)

Code before:
        $request->setTcpConnectTimeout($options['timeout']);
        $request->setTlsHandshakeTimeout($options['timeout']);
        $request->setTransferTimeout($options['max_duration']);
        $request->setInactivityTimeout(0);

        if ('' !== $request->getUri()->getUserInfo() && !$request->hasHeader('authorization')) {
            $auth = explode(':', $request->getUri()->getUserInfo(), 2);
            $auth = array_map('rawurldecode', $auth) + [1 => ''];
            $request->setHeader('Authorization', 'Basic '.base64_encode(implode(':', $auth)));
        }

        return new AmpResponse($this->multi, $request, $options, $this->logger);
    }

    public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
    {
        if ($responses instanceof AmpResponse) {
            $responses = [$responses];
        }

        return new ResponseStream(AmpResponse::stream($responses, $timeout));
    }

    public function reset(): void
    {
        if (!$this->defaultOptions['use_persistent_connections']) {
            $this->multi->dnsCache = [];
        }

        foreach ($this->multi->pushedResponses as $pushedResponses) {
            foreach ($pushedResponses as [$pushedUrl, $pushDeferred]) {
                $pushDeferred->error(new CancelledException());

                $this->logger?->debug(\sprintf('Unused pushed response: "%s"', $pushedUrl));
            }
        }

        $this->multi->pushedResponses = [];
    }
}


Review comment (suggestion):
Nah, let's not do this. That's not about sharing connection state so better reset.

That being said, maybe I did in the past, but today I've no idea how AMP reuses connections.
Either it's shared already, or it's not at all even in the same request. Worth investigating...

Code after:
        $request->setTransferTimeout($options['max_duration']);
        $request->setInactivityTimeout(0);

        if ('' !== $request->getUri()->getUserInfo() && !$request->hasHeader('authorization')) {
            $auth = explode(':', $request->getUri()->getUserInfo(), 2);
            $auth = array_map('rawurldecode', $auth) + [1 => ''];
            $request->setHeader('Authorization', 'Basic '.base64_encode(implode(':', $auth)));
        }

        return new AmpResponse($this->multi, $request, $options, $this->logger);
    }

    public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
    {
        if ($responses instanceof AmpResponse) {
            $responses = [$responses];
        }

        return new ResponseStream(AmpResponse::stream($responses, $timeout));
    }

    public function reset(): void
    {
        $this->multi->dnsCache = [];

        foreach ($this->multi->pushedResponses as $pushedResponses) {
            foreach ($pushedResponses as [$pushedUrl, $pushDeferred]) {
                $pushDeferred->error(new CancelledException());

                $this->logger?->debug(\sprintf('Unused pushed response: "%s"', $pushedUrl));
            }
        }

        $this->multi->pushedResponses = [];
    }
}