code cleanup
This commit is contained in:
parent
78d0783b00
commit
a0efdca18b
29
src/main.rs
29
src/main.rs
|
@ -165,16 +165,9 @@ fn handle_sync_api_request<'a>(
|
|||
Box::new(resp)
|
||||
}
|
||||
|
||||
fn handle_static_file_download(filename: PathBuf) -> BoxFut {
|
||||
fn simple_static_file_download(filename: PathBuf) -> BoxFut {
|
||||
|
||||
let response = tokio::fs::metadata(filename.clone())
|
||||
.map_err(|err| format_err!("File access problems: {}", err))
|
||||
.and_then(|metadata| {
|
||||
println!("TEST METADATA {:?} {}", metadata, metadata.len());
|
||||
|
||||
if metadata.len() < 1024*8 {
|
||||
println!("SMALL SIZED FILE");
|
||||
Either::A(File::open(filename)
|
||||
Box::new(File::open(filename)
|
||||
.map_err(|err| format_err!("File open failed: {}", err))
|
||||
.and_then(|file| {
|
||||
let buf: Vec<u8> = Vec::new();
|
||||
|
@ -182,10 +175,11 @@ fn handle_static_file_download(filename: PathBuf) -> BoxFut {
|
|||
.map_err(|err| format_err!("File read failed: {}", err))
|
||||
.and_then(|data| Ok(Response::new(data.1.into())))
|
||||
}))
|
||||
}
|
||||
|
||||
} else {
|
||||
Either::B(
|
||||
File::open(filename)
|
||||
fn chuncked_static_file_download(filename: PathBuf) -> BoxFut {
|
||||
|
||||
Box::new(File::open(filename)
|
||||
.map_err(|err| format_err!("File open failed: {}", err))
|
||||
.and_then(|file| {
|
||||
let payload = tokio_codec::FramedRead::new(file, tokio_codec::BytesCodec::new()).
|
||||
|
@ -200,6 +194,17 @@ fn handle_static_file_download(filename: PathBuf) -> BoxFut {
|
|||
.body(body)
|
||||
.unwrap())
|
||||
}))
|
||||
}
|
||||
|
||||
fn handle_static_file_download(filename: PathBuf) -> BoxFut {
|
||||
|
||||
let response = tokio::fs::metadata(filename.clone())
|
||||
.map_err(|err| format_err!("File access problems: {}", err))
|
||||
.and_then(|metadata| {
|
||||
if metadata.len() < 1024*32 {
|
||||
Either::A(simple_static_file_download(filename))
|
||||
} else {
|
||||
Either::B(chuncked_static_file_download(filename))
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue