title: laravel response stream download returns empty file
body: <p>I have a controller method that receives user's request for download, calls REST API endpoint with the requested body parameters.</p>
  
  <p>API, in return, sends a file.</p>
  
  <p>I am using Guzzle for making API requests and laravel version <code>5.4</code>.</p>
  
  <p>The content of the <code>$response-&gt;getBody()-&gt;getContents();</code> is as :</p>
  
  <pre><code>"""
  request_id\ts_sku\tr_product_url\thuman_verdict\n
  199\tSG-948\thttps://www.amazon.com/gp/offer-listing/B076CP7J4P?condition=new\tMatch\n
  199\tZIB-601\thttps://www.amazon.com/gp/offer-listing/B07D9PN39C?condition=new\tMatch\n
  199\tRCM-LG526\thttps://www.amazon.com/gp/offer-listing/B07FDJ3W7P?condition=new\tMatch\n
  199\tGSI-335\thttps://www.amazon.com/gp/offer-listing/B07GNX1VSG?condition=new\tMatch\n
  199\tZIB-489\thttps://www.amazon.com/gp/offer-listing/B07D9RCGXM?condition=new\tMatch\n
  """
  </code></pre>
  
  <p>Also the received header response from API is:</p>
  
  <pre><code>Content-Type : ('text/tab-separated-values', none)
  Content-Disposition : attachment; filename=/path/to/file1.tsv
  </code></pre>
  
  <p>I am trying to receive this file in my controller and return response as stream download to user's browser.</p>
  
  <p>Here's controller method:</p>
  
  <pre><code>    $client = new Client(["base_uri" =&gt; $this-&gt;apiBaseUrl]);
      $url = 'download/filterdownload/';
  
      try {
          $response = $client-&gt;request('POST', $url, ['headers'=&gt;['Content-Type' =&gt; 'application/json'], 'body'=&gt;json_encode($filterArr)]);
          # $resArr = json_decode($response, true);
      } catch (\Exception $e) {
          return redirect()-&gt;back()-&gt;with('error', $e-&gt;getMessage());
      }
  
      if(!empty($resArr) &amp;&amp; array_key_exists('response', $resArr))
          return redirect()-&gt;back()-&gt;with('error', $resArr['response']);
  
      # return response
      $file = $response-&gt;getBody()-&gt;getContents();
  
      $file_name = $filterArr['client_name'].'_'.Carbon::now()-&gt;toDateString().'.tsv';
      $headers = [
          'Content-Disposition' =&gt; 'attachment; filename='. $file_name. ';'
      ];
      return response()-&gt;stream(function () {
          $file;
      }, 200, $headers);
  </code></pre>
  
  <p>This downloads a file but the file is empty.</p>