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

Fields

ssl: bool

Implementations

Generates default settings (which don’t work by itself)

Chain with mount_point or routes

Example:
use tinyhttp::config::*;
use tinyhttp::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(".");

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.

Add routes with a Route member

Example:
use tinyhttp::config::*;
use tinyhttp::tinyhttp_codegen::*;


#[get("/test")]
fn get_test() -> &'static str {
  "Hello, World!"
}

#[post("/test")]
fn post_test(body: Vec<u8>) -> 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();
}

Enables SSL

Example:
let config = Config::new().ssl("./fullchain.pem", "./privkey.pem");

This will only accept HTTPS connections

Define custom headers

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

DOES NOT WORK! Enables brotli compression

Enables gzip compression

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.