- main
- manifest
- deps
- main
- Install
- Run
use fastly::http::StatusCode;
use fastly::{Error, Request, Response};
use std::ffi::OsStr;
use std::path::Path;
const BLOCK_FILE_EXT_LIST: &[&str] = &["exe", "dll", "zip"];
#[fastly::main]
fn main(req: Request) -> Result<Response, Error> {
let path = req.get_path();
if let Some(ext) = Path::new(path).extension().and_then(OsStr::to_str) {
let ext_lowercase = ext.to_lowercase();
if BLOCK_FILE_EXT_LIST.contains(&ext_lowercase.as_str()) {
return Ok(Response::from_status(StatusCode::FORBIDDEN));
}
}
Ok(req.send("origin_0")?)
}