1
0
mirror of https://github.com/actix/actix-website synced 2024-12-04 04:31:55 +01:00
actix-website/examples/static-files/src/configuration.rs

25 lines
759 B
Rust
Raw Normal View History

2019-06-17 23:35:47 +02:00
// <config-one>
2019-06-26 10:27:25 +02:00
use actix_files as fs;
use actix_web::http::header::{ContentDisposition, DispositionType};
use actix_web::{web, App, Error, HttpRequest, HttpServer};
2019-06-17 23:35:47 +02:00
2019-06-26 10:27:25 +02:00
fn index(req: HttpRequest) -> Result<fs::NamedFile, Error> {
let path: std::path::PathBuf = req.match_info().query("filename").parse().unwrap();
let file = fs::NamedFile::open(path)?;
Ok(file
.use_last_modified(true)
.set_content_disposition(ContentDisposition {
disposition: DispositionType::Attachment,
parameters: vec![],
}))
}
2019-06-17 23:35:47 +02:00
2019-06-26 10:27:25 +02:00
pub fn main() {
HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}
2019-06-17 23:35:47 +02:00
// </config-one>