title: Flask proxy response for file download
body: <p>I am using a Flask route as a proxy to download a file, like this:</p>
  <pre><code>@esa_handler.route(&quot;/data/&lt;int:series&gt;/&lt;int:file_num&gt;&quot;, methods=[&quot;GET&quot;])
  def DownloadRemote(series, file_num):
      &quot;&quot;&quot;
      Downloads the remote files from the ESA.
      :param series: 0-20.
      :param file_num: File within the series, 0-255
      :return: Compressed CSV file.
      &quot;&quot;&quot;
  
      # if the file is bad.
      if series &gt;= 20 and file_num &gt; 110:
          return jsonify({&quot;error&quot;: &quot;file does not exist.&quot;})
  
      url = &quot;http://cdn.gea.esac.esa.int/Gaia/gaia_source/csv/GaiaSource_000-{:03d}-{:03d}.csv.gz&quot;.format(series,
                                                                                                          file_num)
      req = requests.get(url, stream=True)
      return Response(stream_with_context(req.iter_content(chunk_size=2048)), content_type=req.headers[&quot;content-type&quot;])
  </code></pre>
  <p>It works fine, however, the filename that is presented to the client is whatever the file number that is passed to the endpoint. For example, if I put <code>http://127.0.0.1:5000/esa/data/0/0</code> to download the very first file, it downloads, but Chrome/Firefox/IE/Edge are offering to save the file with a filename as &quot;0&quot;. While there is nothing wrong with that, I would like a better user experience.</p>
  <p>How can I intercept the response to proffer a filename based off the URL requested?</p>