1 use std
::path
::PathBuf
;
4 use hyper
::{Body, Response, StatusCode, header}
;
7 pub async
fn create_download_response(path
: PathBuf
) -> Result
<Response
<Body
>, Error
> {
8 let file
= tokio
::fs
::File
::open(path
.clone())
9 .map_err(move |err
| http_err
!(BAD_REQUEST
, format
!("open file {:?} failed: {}", path
.clone(), err
)))
12 let payload
= tokio_util
::codec
::FramedRead
::new(file
, tokio_util
::codec
::BytesCodec
::new())
13 .map_ok(|bytes
| hyper
::body
::Bytes
::from(bytes
.freeze()));
15 let body
= Body
::wrap_stream(payload
);
17 // fixme: set other headers ?
18 Ok(Response
::builder()
19 .status(StatusCode
::OK
)
20 .header(header
::CONTENT_TYPE
, "application/octet-stream")