title: Laravel - Using Stream with the new Http client
body: <p>I'm migrating my old system to the new version of Laravel, and I'm having problems with one of my requests...</p>
  
  <p>Basically on this request I receive any file and simply forward it to the user. Here is the old version using <code>Guzzle</code>:</p>
  
  <pre><code>use Symfony\Component\HttpFoundation\StreamedResponse;
  
  public function getMedia($media)
  {
      try {
          $response = $this-&gt;client-&gt;get('media/' . $media, [
                  'stream' =&gt; true
              ]
          );
  
          $contentType = $response-&gt;getHeader('Content-Type');
  
          $body = $response-&gt;getBody();
  
          $stream = new StreamedResponse(function () use ($body) {
              while (!$body-&gt;eof()) {
                  echo $body-&gt;read(1024);
              }
          });
  
          $stream-&gt;headers-&gt;set('Content-Type', $contentType);
  
          return $stream;
      } catch (ClientException $e) {
          return response()-&gt;json([
              'errors' =&gt; json_decode($e-&gt;getResponse()-&gt;getBody()-&gt;getContents())-&gt;errors,
              'message' =&gt; 'Unfortunately we could not find the requested file'
          ], 404);
      }
  }
  </code></pre>
  
  <p>And the new code that I tried to write, without success:</p>
  
  <pre><code>use Symfony\Component\HttpFoundation\StreamedResponse;
  
  public function getMedia($media)
  {
      $response = Http::withOptions([
          'stream' =&gt; true
      ])-&gt;get("media/{$media}");
  
      $contentType = $response-&gt;header('Content-Type');
  
      $body = $response-&gt;body();
  
      $stream = new StreamedResponse(function () use ($body) {
          while (!$body-&gt;eof()) {
              echo $body-&gt;read(1024);
          }
      });
  
      $stream-&gt;headers-&gt;set('Content-Type', $contentType);
  
      return $stream;
  }
  </code></pre>
  
  <p>Does anyone have any idea how to solve this? I don't know what to do anymore...</p>