use hyper::header::{ HeaderName, HeaderValue, CACHE_CONTROL, CONTENT_TYPE, LOCATION, SET_COOKIE, }; use hyper::{Body, Response, StatusCode}; use std::collections::HashMap; use tera::{Context, Tera}; use tokio::fs::File; use tokio_util::codec::{BytesCodec, FramedRead}; use uuid::Uuid; use crate::controller::error; use crate::model::config::Config; pub fn with_header( response: Response
, name: HeaderName, value: &str, ) -> Response { with_headers(response, vec![(name, value)]) } pub fn with_headers( response: Response, headers: Vec<(HeaderName, &str)>, ) -> Response { let mut response = response; let response_headers = response.headers_mut(); for (name, value) in headers { response_headers.insert(name, HeaderValue::from_str(value).unwrap()); } response } pub fn with_login_cookie( config: Config, login_token: Uuid, response: Response, ) -> Response { let cookie = format!( "TOKEN={}; SameSite=Strict; HttpOnly; Max-Age=86400{}", login_token, if config.secure_cookies { "; Secure" } else { "" } ); with_header(response, SET_COOKIE, &cookie) } pub fn with_logout_cookie( config: Config, response: Response, ) -> Response { let cookie = format!( "TOKEN=; SameSite=Strict; HttpOnly; Max-Age=0{}", if config.secure_cookies { "; Secure" } else { "" } ); with_header(response, SET_COOKIE, &cookie) } pub fn template( assets: &HashMap