Struct tinyhttp_internal::config::Config
source · [−]pub struct Config {
pub ssl: bool,
/* private fields */
}
Fields
ssl: bool
Implementations
sourceimpl 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::internal::config::*;
use tinyhttp::codegen::*;
#[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
A mount point that will be searched when a request isn’t defined with a get or post route
Example:
ⓘ
let config = Config::new().mount_point(".")
/// if index.html exists in current directory, it will be returned if "/" or "/index.html" is requested.
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();
}
sourcepub fn ssl(self, ssl_chain: String, ssl_priv: String) -> Self
pub fn ssl(self, ssl_chain: String, ssl_priv: String) -> Self
Enables SSL
Example:
ⓘ
let config = Config::new().ssl("./fullchain.pem", "./privkey.pem");
This will only accept HTTPS connections
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 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, path: &mut String) -> Option<Box<dyn Route>>
pub fn post_routes(&self, path: &mut String) -> Option<Box<dyn Route>>
pub fn get_spa(&self) -> bool
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more