Struct tinyhttp_internal::config::Config
source · 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::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
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()]);