title: Rust + rocket: Return file using `NamedFile` gives wrong file extension
body: <p>Using <code>xlsxwriter</code>, I have created an .xlsx file ( <code>fn create_workbook()</code>) that I want to send to the client using <code>rocket</code>. Downloading works, but the extension is wrong. Ideally, the file should be deleted after the client has downloaded it.</p>
  <p>Creating the file works (it's stored under <code>target/simple1.xlsx</code>), however, the file that gets downloaded upon visiting <a href="http://127.0.0.1:8000" rel="nofollow noreferrer">http://127.0.0.1:8000</a>
  is a <code>.dms</code> file rather than a <code>.xlsx</code> file. Apparently, the problem is only the file name (and hence, also the extension): If one changes the extension of the downloaded file to <code>.xlsx</code>, it is the desired document.</p>
  <p>Also, I don't know how to delete the file after it has been downloaded from the server, since the function will be exited right after it has been downloaded. (I'm new to rust and also happy about any code recommendations)</p>
  <pre><code>use std::fs;
  use std::path;
  use rocket::{
      response::status::NotFound,
      fs::{FileServer,
           NamedFile}
  };
  use xlsxwriter::Workbook;
  
  #[macro_use] extern crate rocket;
  
  // create an xlsx workbook at &quot;target/simple1.xlsx&quot;
  fn create_workbook()-&gt;Result&lt;Vec&lt;u8&gt;,xlsxwriter::XlsxError&gt;{
      let workbook = Workbook::new(&quot;target/simple1.xlsx&quot;);
      let mut sheet1 = workbook.add_worksheet(None)?;
      sheet1.write_string(2,1,&quot;Hello, world!&quot;,None)?;
      workbook.close().expect(&quot;workbook can be closed&quot;);
      let result = fs::read(&quot;target/simple1.xlsx&quot;).expect(&quot;can read file&quot;);
      Ok(result)
  }
  
  
  #[get(&quot;/&quot;)]
  async fn index() -&gt; NamedFile  {
      let file = create_workbook().expect(&quot;file can be created&quot;);
      let path_to_file = path::Path::new(&quot;target/simple1.xlsx&quot;);
      let res = NamedFile::open(&amp;path_to_file).await.map_err(|e| NotFound(e.to_string()));
      match res {
          Ok(file) =&gt; file,
          Err(error) =&gt; panic!(&quot;Problem with file {:?}&quot;, error),
      }
      // ideally, the file would be deleted after it has been sent to the client
      // fs::remove_file(&quot;target/simple1.xlsx&quot;).expect(&quot;can delete file&quot;);
  }
  
  #[launch]
  fn rocket() -&gt; _ {
      let rocket= rocket::build();
      rocket
          .mount(&quot;/&quot;, routes![index])
  }
  </code></pre>
  <p>The <code>Cargo.toml</code> file is:</p>
  <pre><code>[package]
  name = &quot;demo_download_xlsx_rust&quot;
  version = &quot;0.1.0&quot;
  edition = &quot;2021&quot;
  
  [dependencies]
  xlsxwriter = &quot;0.4.0&quot;
  
  [dependencies.rocket]
  version = &quot;0.5.0-rc.2&quot;
  </code></pre>
  <p>I followed the <code>Response</code> guide as closely as possible (<a href="https://rocket.rs/v0.5-rc/guide/responses/#rocket-responders" rel="nofollow noreferrer">doc</a>). I also tried returning a <code>Result&lt;NamedFile, NotFound&lt;String&gt;&gt;</code>.</p>