pub struct Config {
pub ssl: bool,
/* private fields */
}
Fields§
§ssl: bool
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Config
pub fn new() -> Config
Generates default settings (which don’t work by itself)
Chain with mount_point or routes
§Example:
ⓘ
use tinyhttp::prelude::*;
#[get("/test")]
fn get_test() -> String {
String::from("Hello, there!\n")
}
let routes = Routes::new(vec![get_test()]);
let routes_config = Config::new().routes(routes);
/// or
let mount_config = Config::new().mount_point(".");
Sourcepub fn mount_point<P: Into<String>>(self, path: P) -> Self
pub fn mount_point<P: Into<String>>(self, path: P) -> Self
Sourcepub fn routes(self, routes: Routes) -> Self
pub fn routes(self, routes: Routes) -> Self
Add routes with a Route member
§Example:
ⓘ
use tinyhttp::prelude::*;
#[get("/test")]
fn get_test() -> &'static str {
"Hello, World!"
}
#[post("/test")]
fn post_test() -> Vec<u8> {
b"Hello, Post!".to_vec()
}
fn main() {
let socket = TcpListener::new(":::80").unwrap();
let routes = Routes::new(vec![get_test(), post_test()]);
let config = Config::new().routes(routes);
let http = HttpListener::new(socket, config);
http.start();
}
pub fn debug(self) -> Self
Sourcepub fn headers(self, headers: Vec<String>) -> Self
pub fn headers(self, headers: Vec<String>) -> Self
Define custom headers
ⓘ
let config = Config::new().headers(vec!["Access-Control-Allow-Origin: *".into()]);
pub fn spa(self, res: bool) -> Self
pub fn http2(self, res: bool) -> Self
pub fn request_middleware<F: FnMut(&mut Request) + Send + Sync + 'static>( self, middleware_fn: F, ) -> Self
pub fn response_middleware<F: FnMut(&mut Response) + Send + Sync + 'static>( self, middleware_fn: F, ) -> Self
pub fn get_headers(&self) -> Option<&HashMap<String, String>>
pub fn get_br(&self) -> bool
pub fn get_gzip(&self) -> bool
pub fn get_debug(&self) -> bool
pub fn get_mount(&self) -> Option<&String>
pub fn get_routes(&self, req_path: &str) -> Option<&dyn Route>
pub fn post_routes(&self, req_path: &str) -> Option<&dyn Route>
pub fn get_spa(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl !RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more