Files
aweblib/src/renderer.rs
2024-12-02 18:21:48 +01:00

26 lines
700 B
Rust

use crate::body::Body;
use hyper::{Response, StatusCode};
use std::fs::File;
use std::io::Read;
pub(crate) fn get_static(file: &String) -> Response<Body> {
let file = read_static(file);
match file {
Ok(file) => Response::new(Body::new(file)),
Err(_) => Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::Empty)
.unwrap(),
}
}
pub(crate) fn get_rendered(file: &String) -> Response<Body> {
todo!()
}
fn read_static(file: &String) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> {
let mut buf = Vec::new();
let mut file = File::open(file)?;
file.read_to_end(&mut buf)?;
Ok(buf)
}