Struct Config

Source
pub struct Config {
    pub ssl: bool,
    /* private fields */
}

Fields§

§ssl: bool

Implementations§

Source§

impl Config

Source

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(".");
Source

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.
Source

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();
}
Source

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

Source

pub fn debug(self) -> Self

Source

pub fn headers(self, headers: Vec<String>) -> Self

Define custom headers

let config = Config::new().headers(vec!["Access-Control-Allow-Origin: *".into()]);
Source

pub fn br(self, res: bool) -> Self

DOES NOT WORK! Enables brotli compression

Source

pub fn spa(self, res: bool) -> Self

Source

pub fn gzip(self, res: bool) -> Self

Enables gzip compression

Source

pub fn http2(self, res: bool) -> Self

Source

pub fn request_middleware<F: FnMut(&mut Request) + Send + Sync + 'static>( self, middleware_fn: F, ) -> Self

Source

pub fn response_middleware<F: FnMut(&mut Response) + Send + Sync + 'static>( self, middleware_fn: F, ) -> Self

Source

pub fn get_headers(&self) -> Option<&HashMap<String, String>>

Source

pub fn get_br(&self) -> bool

Source

pub fn get_gzip(&self) -> bool

Source

pub fn get_debug(&self) -> bool

Source

pub fn get_mount(&self) -> Option<&String>

Source

pub fn get_routes(&self, req_path: &str) -> Option<&dyn Route>

Source

pub fn post_routes(&self, req_path: &str) -> Option<&dyn Route>

Source

pub fn get_spa(&self) -> bool

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.