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

Code before:
                $info['size_download'] = $dlNow;
            } elseif (\STREAM_NOTIFY_CONNECT === $code) {
                $info['connect_time'] = $info['total_time'];
                $info['debug'] .= $info['request_header'];
                unset($info['request_header']);
            } else {
                return;
            }

            if ($onProgress) {
                $onProgress($dlNow, $dlSize);
            }
        };

        if ($options['resolve']) {
            $this->multi->dnsCache = $options['resolve'] + $this->multi->dnsCache;
        }

        $this->logger?->info(\sprintf('Request: "%s %s"', $method, implode('', $url)));

        if (!isset($options['normalized_headers']['user-agent'])) {
            $options['headers'][] = 'User-Agent: Symfony HttpClient (Native)';
        }

        if (0 < $options['max_connect_duration']) {
            $options['timeout'] = min($options['max_connect_duration'], $options['timeout']);
        }

        if (0 < $options['max_duration']) {
            $options['timeout'] = min($options['max_duration'], $options['timeout']);
        }

        switch ($cryptoMethod = $options['crypto_method']) {
            case \STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT:
                $cryptoMethod |= \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
                // no break
            case \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT:
                $cryptoMethod |= \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
                // no break
            case \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT:
                $cryptoMethod |= \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT;
        }

        $context = [
            'http' => [
                'protocol_version' => min($options['http_version'] ?: '1.1', '1.1'),
                'method' => $method,
                'content' => $options['body'],
                'ignore_errors' => true,
                'curl_verify_ssl_peer' => $options['verify_peer'],
                'curl_verify_ssl_host' => $options['verify_host'],

Review comment (suggestion):
This timeout should be used only for the fopen stage.
This means only the $context array below should get this logic to me.

Code after:
                $info['size_download'] = $dlNow;
            } elseif (\STREAM_NOTIFY_CONNECT === $code) {
                $info['connect_time'] = $info['total_time'];
                $info['debug'] .= $info['request_header'];
                unset($info['request_header']);
            } else {
                return;
            }

            if ($onProgress) {
                $onProgress($dlNow, $dlSize);
            }
        };

        if ($options['resolve']) {
            $this->multi->dnsCache = $options['resolve'] + $this->multi->dnsCache;
        }

        $this->logger?->info(\sprintf('Request: "%s %s"', $method, implode('', $url)));

        if (!isset($options['normalized_headers']['user-agent'])) {
            $options['headers'][] = 'User-Agent: Symfony HttpClient (Native)';
        }

        if (0 < $options['max_duration']) {
            $options['timeout'] = min($options['max_duration'], $options['timeout']);
        }

        switch ($cryptoMethod = $options['crypto_method']) {
            case \STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT:
                $cryptoMethod |= \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
                // no break
            case \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT:
                $cryptoMethod |= \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
                // no break
            case \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT:
                $cryptoMethod |= \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT;
        }

        $context = [
            'http' => [
                'protocol_version' => min($options['http_version'] ?: '1.1', '1.1'),
                'method' => $method,
                'content' => $options['body'],
                'ignore_errors' => true,
                'curl_verify_ssl_peer' => $options['verify_peer'],
                'curl_verify_ssl_host' => $options['verify_host'],
                'auto_decode' => false, // Disable dechunk filter, it's incompatible with stream_select()
                'timeout' => 0 < $options['max_connect_duration'] ? min($options['timeout'], $options['max_connect_duration']) : $options['timeout'],
                'follow_location' => false, // We follow redirects ourselves - the native logic is too limited
            ],