mirror of
https://github.com/actix/actix-website
synced 2025-01-23 00:25:55 +01:00
26 lines
785 B
Rust
26 lines
785 B
Rust
// <config-one>
|
|
use actix_files as fs;
|
|
use actix_web::http::header::{ContentDisposition, DispositionType};
|
|
use actix_web::{get, App, Error, HttpRequest, HttpServer};
|
|
|
|
#[get("/{filename:.*}")]
|
|
async 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![],
|
|
}))
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| App::new().service(index))
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|
|
// </config-one>
|