2019-08-20 23:53:00 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2016-09-12 09:43:34 +00:00
|
|
|
|
2018-06-28 15:55:15 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2016-09-12 09:43:34 +00:00
|
|
|
|
2017-05-25 05:45:03 +00:00
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
2016-10-25 11:03:50 +00:00
|
|
|
use rocket::response::{content, Stream};
|
2016-09-12 09:43:34 +00:00
|
|
|
|
2019-09-22 22:48:08 +00:00
|
|
|
use tokio::fs::File;
|
2019-12-11 00:34:23 +00:00
|
|
|
use tokio::io::{repeat, AsyncRead, AsyncReadExt};
|
2016-09-12 09:43:34 +00:00
|
|
|
|
2017-05-25 05:45:03 +00:00
|
|
|
// Generate this file using: head -c BYTES /dev/random > big_file.dat
|
2018-07-28 16:58:10 +00:00
|
|
|
const FILENAME: &str = "big_file.dat";
|
2017-05-25 05:45:03 +00:00
|
|
|
|
2016-09-12 09:43:34 +00:00
|
|
|
#[get("/")]
|
2019-09-22 22:48:08 +00:00
|
|
|
fn root() -> content::Plain<Stream<impl AsyncRead>> {
|
2019-12-11 00:34:23 +00:00
|
|
|
content::Plain(Stream::from(repeat('a' as u8).take(25000)))
|
2016-09-12 09:43:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-25 11:07:03 +00:00
|
|
|
#[get("/big_file")]
|
2019-08-29 01:32:32 +00:00
|
|
|
async fn file() -> Option<Stream<File>> {
|
|
|
|
File::open(FILENAME).await.map(Stream::from).ok()
|
2016-09-25 11:07:03 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 05:45:03 +00:00
|
|
|
fn rocket() -> rocket::Rocket {
|
|
|
|
rocket::ignite().mount("/", routes![root, file])
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:43:34 +00:00
|
|
|
fn main() {
|
2019-08-25 02:19:11 +00:00
|
|
|
let _ = rocket().launch();
|
2016-09-12 09:43:34 +00:00
|
|
|
}
|