How to convert cUrl code to drupal way?
The only special thing I see there is getting the effective URL, which is actually something that was specifically added back to Guzzle 6 for Drupal: https://github.com/guzzle/guzzle/issues/1166

See \Drupal\aggregator\Plugin\aggregator\fetcher\DefaultFetcher::fetch:

  /** @var \Psr\Http\Message\UriInterface $actual_uri */
  $actual_uri = NULL;
  $response = $this-&gt;httpClientFactory-&gt;fromOptions([
    'allow_redirects' =&gt; [
      'on_redirect' =&gt; function (RequestInterface $request, ResponseInterface $response, UriInterface $uri) use (&amp;$actual_uri) {
        $actual_uri = (string) $uri;
      }
    ],
  ])-&gt;send($request);