@@ -3,6 +3,7 @@ use async_std::io::{self, Cursor};
33use serde:: { de:: DeserializeOwned , Serialize } ;
44
55use std:: fmt:: { self , Debug } ;
6+ use std:: path:: PathBuf ;
67use std:: pin:: Pin ;
78use std:: task:: { Context , Poll } ;
89
@@ -57,6 +58,7 @@ pin_project_lite::pin_project! {
5758 reader: Box <dyn BufRead + Unpin + Send + Sync + ' static >,
5859 mime: Mime ,
5960 length: Option <usize >,
61+ pub ( crate ) file_name: Option <PathBuf >,
6062 }
6163}
6264
@@ -79,6 +81,7 @@ impl Body {
7981 reader : Box :: new ( io:: empty ( ) ) ,
8082 mime : mime:: BYTE_STREAM ,
8183 length : Some ( 0 ) ,
84+ file_name : None ,
8285 }
8386 }
8487
@@ -109,6 +112,7 @@ impl Body {
109112 reader : Box :: new ( reader) ,
110113 mime : mime:: BYTE_STREAM ,
111114 length : len,
115+ file_name : None ,
112116 }
113117 }
114118
@@ -152,6 +156,7 @@ impl Body {
152156 mime : mime:: BYTE_STREAM ,
153157 length : Some ( bytes. len ( ) ) ,
154158 reader : Box :: new ( io:: Cursor :: new ( bytes) ) ,
159+ file_name : None ,
155160 }
156161 }
157162
@@ -201,6 +206,7 @@ impl Body {
201206 mime : mime:: PLAIN ,
202207 length : Some ( s. len ( ) ) ,
203208 reader : Box :: new ( io:: Cursor :: new ( s. into_bytes ( ) ) ) ,
209+ file_name : None ,
204210 }
205211 }
206212
@@ -248,6 +254,7 @@ impl Body {
248254 length : Some ( bytes. len ( ) ) ,
249255 reader : Box :: new ( Cursor :: new ( bytes) ) ,
250256 mime : mime:: JSON ,
257+ file_name : None ,
251258 } ;
252259 Ok ( body)
253260 }
@@ -312,6 +319,7 @@ impl Body {
312319 length : Some ( bytes. len ( ) ) ,
313320 reader : Box :: new ( Cursor :: new ( bytes) ) ,
314321 mime : mime:: FORM ,
322+ file_name : None ,
315323 } ;
316324 Ok ( body)
317325 }
@@ -366,7 +374,7 @@ impl Body {
366374 P : AsRef < std:: path:: Path > ,
367375 {
368376 let path = path. as_ref ( ) ;
369- let mut file = async_std:: fs:: File :: open ( path) . await ?;
377+ let mut file = async_std:: fs:: File :: open ( & path) . await ?;
370378 let len = file. metadata ( ) . await ?. len ( ) ;
371379
372380 // Look at magic bytes first, look at extension second, fall back to
@@ -380,6 +388,7 @@ impl Body {
380388 mime,
381389 length : Some ( len as usize ) ,
382390 reader : Box :: new ( io:: BufReader :: new ( file) ) ,
391+ file_name : Some ( path. to_path_buf ( ) ) ,
383392 } )
384393 }
385394
0 commit comments