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::internal::config::*;
use tinyhttp::codegen::*;
use tinyhttp::internal::request::Request
#[get("/test")]
fn get_test() -> &'static str {
"Hello, World!"
}
#[post("/test")]
fn post_test(body: Request) -> Vec<u8> {
"Hello, Post!".into()
}
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<P: Into<Vec<String>>>(self, headers: P) -> Self
pub fn headers<P: Into<Vec<String>>>(self, headers: P) -> 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<Vec<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: String
) -> Option<(String, fn(_: Request) -> Vec<u8>, Option<String>)>
pub fn post_routes(
&self
) -> Option<Vec<(String, fn(_: Request) -> Vec<u8>, Option<String>)>>
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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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