2016-09-12 09:43:34 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
2016-09-21 03:02:33 +00:00
|
|
|
use rocket::response::{data, Stream};
|
2016-09-12 09:43:34 +00:00
|
|
|
|
2016-09-25 11:07:03 +00:00
|
|
|
use std::io::{self, repeat, Repeat, Read, Take};
|
|
|
|
use std::fs::File;
|
2016-09-12 09:43:34 +00:00
|
|
|
|
|
|
|
type LimitedRepeat = Take<Repeat>;
|
|
|
|
|
|
|
|
#[get("/")]
|
2016-09-21 03:02:33 +00:00
|
|
|
fn root() -> data::Plain<Stream<LimitedRepeat>> {
|
|
|
|
data::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")]
|
|
|
|
fn file() -> io::Result<Stream<File>> {
|
|
|
|
// Generate this file using: head -c BYTES /dev/random > big_file.dat
|
|
|
|
const FILENAME: &'static str = "big_file.dat";
|
|
|
|
File::open(FILENAME).map(|file| Stream::from(file))
|
|
|
|
}
|
|
|
|
|
2016-09-12 09:43:34 +00:00
|
|
|
fn main() {
|
2016-10-04 02:48:33 +00:00
|
|
|
rocket::ignite().mount("/", routes![root, file]).launch();
|
2016-09-12 09:43:34 +00:00
|
|
|
}
|