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::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(".");
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 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(&mut self, path: &mut String) -> Option<Box<dyn Route>>

source

pub fn post_routes(&mut self, path: &mut String) -> Option<Box<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 !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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.