A modular HTTP server library in Rust.
forbid(unsafe_code)
FnOnce(Request) -> Response + 'static + Clone + Send + Sync
chunked
transfer-encoding for request bodiesComplete examples: examples/
.
Simple example: ```rust use serde::Deserialize; use serdejson::json; use servlin::{ socketaddr127001, Error, HttpServerBuilder, Request, Response }; use servlin::log::logrequestandresponse; use servlin::reexport::{safinaexecutor, safinatimer}; use std::sync::Arc; use tempdir::TempDir;
struct State {}
fn hello(_state: Arc
fn handle_req(state: Arc
let state = Arc::new(State {}); let requesthandler = move |req: Request| { logrequestandresponse(req, |req| handlereq(state, req)) }; let cachedir = TempDir::new().unwrap(); safinatimer::starttimerthread(); let executor = safinaexecutor::Executor::new(1, 9).unwrap(); executor.blockon( HttpServerBuilder::new() .listenaddr(socketaddr127001(8009)) .maxconns(1000) .smallbodylen(64 * 1024) .receivelargebodies(cachedir.path()) .spawnandjoin(requesthandler) ).unwrap(); ```
```
Metric output format: x/y x = unsafe code used by the build y = total unsafe code found in the crate
Symbols:
🔒 = No unsafe
usage found, declares #![forbid(unsafecode)]
❓ = No unsafe
usage found, missing #![forbid(unsafecode)]
☢️ = unsafe
usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/0 0/0 0/0 0/0 🔒 servlin 0.2.0 0/0 0/4 0/0 0/0 0/2 ❓ ├── async-fs 1.6.0 │ [build-dependencies] 0/0 0/0 0/0 0/0 0/0 ❓ │ └── autocfg 1.1.0 0/4 0/91 0/16 0/0 0/1 ❓ │ ├── async-lock 2.7.0 0/0 0/116 0/8 0/0 0/0 ❓ │ │ └── event-listener 2.5.3 0/0 0/28 0/4 0/0 0/0 ❓ │ ├── blocking 1.3.1 0/0 0/0 0/0 0/0 0/0 🔒 │ │ ├── async-channel 1.9.0 0/0 0/168 0/2 0/0 0/1 ❓ │ │ │ ├── concurrent-queue 2.2.0 0/4 0/94 0/16 0/0 0/3 ❓ │ │ │ │ └── crossbeam-utils 0.8.16 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ │ └── cfg-if 1.0.0 0/0 0/116 0/8 0/0 0/0 ❓ │ │ │ ├── event-listener 2.5.3 0/0 0/37 0/2 0/0 0/0 ❓ │ │ │ └── futures-core 0.3.28 0/4 0/91 0/16 0/0 0/1 ❓ │ │ ├── async-lock 2.7.0 0/1 0/858 0/4 0/0 0/12 ❓ │ │ ├── async-task 4.4.0 0/0 0/33 0/2 0/0 0/0 ❓ │ │ ├── atomic-waker 1.1.1 0/0 0/0 0/0 0/0 0/0 🔒 │ │ ├── fastrand 1.9.0 0/0 0/0 0/0 0/0 0/0 ❓ │ │ ├── futures-lite 1.13.0 0/0 0/0 0/0 0/0 0/0 🔒 │ │ │ ├── fastrand 1.9.0 0/0 0/37 0/2 0/0 0/0 ❓ │ │ │ ├── futures-core 0.3.28 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ ├── futures-io 0.3.28 0/37 0/2144 0/0 0/0 0/21 ❓ │ │ │ ├── memchr 2.5.0 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ │ └── libc 0.2.147 0/0 0/0 0/0 0/0 0/0 🔒 │ │ │ ├── parking 2.1.0 0/0 0/175 0/0 0/0 0/2 ❓ │ │ │ ├── pin-project-lite 0.2.10 0/0 0/21 0/0 0/0 0/4 ❓ │ │ │ └── waker-fn 1.1.0 0/2 0/20 0/1 0/0 0/0 ❓ │ │ └── log 0.4.19 0/0 0/5 0/0 0/0 0/0 ❓ │ │ └── serde 1.0.170 0/0 0/0 0/0 0/0 0/0 ❓ │ │ └── serdederive 1.0.170 0/0 0/15 0/0 0/0 0/3 ❓ │ │ ├── proc-macro2 1.0.64 0/0 0/4 0/0 0/0 0/0 ❓ │ │ │ └── unicode-ident 1.0.10 0/0 0/0 0/0 0/0 0/0 ❓ │ │ ├── quote 1.0.29 0/0 0/15 0/0 0/0 0/3 ❓ │ │ │ └── proc-macro2 1.0.64 0/0 0/79 0/3 0/0 0/2 ❓ │ │ └── syn 2.0.25 0/0 0/15 0/0 0/0 0/3 ❓ │ │ ├── proc-macro2 1.0.64 0/0 0/0 0/0 0/0 0/0 ❓ │ │ ├── quote 1.0.29 0/0 0/4 0/0 0/0 0/0 ❓ │ │ └── unicode-ident 1.0.10 0/0 0/0 0/0 0/0 0/0 ❓ │ └── futures-lite 1.13.0 0/0 0/0 0/0 0/0 0/0 🔒 ├── async-net 1.7.0 │ [build-dependencies] 0/0 0/0 0/0 0/0 0/0 ❓ │ └── autocfg 1.1.0 0/0 0/4 0/0 0/0 0/0 ❓ │ ├── async-io 1.13.0 │ │ [build-dependencies] 0/0 0/0 0/0 0/0 0/0 ❓ │ │ └── autocfg 1.1.0 0/4 0/91 0/16 0/0 0/1 ❓ │ │ ├── async-lock 2.7.0 0/0 0/0 0/0 0/0 0/0 ❓ │ │ ├── cfg-if 1.0.0 0/0 0/168 0/2 0/0 0/1 ❓ │ │ ├── concurrent-queue 2.2.0 0/0 0/0 0/0 0/0 0/0 ❓ │ │ ├── futures-lite 1.13.0 0/2 0/20 0/1 0/0 0/0 ❓ │ │ ├── log 0.4.19 0/0 0/0 0/0 0/0 0/0 🔒 │ │ ├── parking 2.1.0 0/1 0/250 0/16 0/4 0/5 ❓ │ │ ├── polling 2.8.0 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ ├── cfg-if 1.0.0 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ ├── libc 0.2.147 0/2 0/20 0/1 0/0 0/0 ❓ │ │ │ └── log 0.4.19 │ │ │ [build-dependencies] 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ └── autocfg 1.1.0 0/371 0/6690 0/2 0/0 0/22 ❓ │ │ ├── rustix 0.37.23 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ ├── bitflags 1.3.2 0/0 0/100 0/0 0/0 0/0 ❓ │ │ │ ├── errno 0.3.1 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ │ └── libc 0.2.147 0/0 0/666 0/36 0/2 0/14 ❓ │ │ │ ├── io-lifetimes 1.0.11 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ │ ├── libc 0.2.147 0/6 0/673 0/4 0/0 0/4 ❓ │ │ │ │ └── socket2 0.4.9 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ │ └── libc 0.2.147 0/0 0/7 0/0 0/0 0/0 ❓ │ │ │ ├── itoa 1.0.8 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ └── libc 0.2.147 │ │ │ [build-dependencies] 0/1 0/201 0/2 0/0 0/4 ❓ │ │ │ └── cc 1.0.79 0/0 0/24 0/0 0/0 0/3 ❓ │ │ ├── slab 0.4.8 │ │ │ [build-dependencies] 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ └── autocfg 1.1.0 0/0 0/5 0/0 0/0 0/0 ❓ │ │ │ └── serde 1.0.170 0/6 0/673 0/4 0/0 0/4 ❓ │ │ ├── socket2 0.4.9 0/0 0/21 0/0 0/0 0/4 ❓ │ │ └── waker-fn 1.1.0 0/0 0/28 0/4 0/0 0/0 ❓ │ ├── blocking 1.3.1 0/0 0/0 0/0 0/0 0/0 ❓ │ └── futures-lite 1.13.0 0/0 0/0 0/0 0/0 0/0 🔒 ├── fixed-buffer 0.5.0 0/0 0/0 0/0 0/0 0/0 ❓ │ └── futures-io 0.3.28 0/0 0/0 0/0 0/0 0/0 ❓ ├── futures-io 0.3.28 0/0 0/0 0/0 0/0 0/0 ❓ ├── futures-lite 1.13.0 0/0 0/0 0/0 0/0 0/0 ❓ ├── includedir 0.7.3 0/0 0/0 0/0 0/0 0/0 ❓ │ └── includedirmacros 0.7.3 0/0 0/15 0/0 0/0 0/3 ❓ │ ├── proc-macro2 1.0.64 0/0 0/0 0/0 0/0 0/0 ❓ │ └── quote 1.0.29 0/0 0/121 0/9 0/0 0/4 ❓ ├── oncecell 1.18.0 0/0 0/0 0/0 0/0 0/0 🔒 ├── permit 0.2.1 0/0 0/32 0/0 0/0 0/0 ❓ ├── rand 0.8.5 0/60 0/502 0/2 0/0 0/50 ❓ │ ├── libc 0.2.147 0/2 0/20 0/1 0/0 0/0 ❓ │ ├── log 0.4.19 0/0 0/0 0/0 0/0 0/0 ❓ │ ├── randchacha 0.3.1 0/2 0/712 0/0 0/0 0/25 ❓ │ │ ├── ppv-lite86 0.2.17 0/0 0/2 0/0 0/0 0/0 ❓ │ │ ├── randcore 0.6.4 0/7 0/228 0/1 0/0 0/3 ❓ │ │ │ ├── getrandom 0.2.10 0/0 0/0 0/0 0/0 0/0 ❓ │ │ │ │ ├── cfg-if 1.0.0 0/60 0/502 0/2 0/0 0/50 ❓ │ │ │ │ └── libc 0.2.147 0/0 0/5 0/0 0/0 0/0 ❓ │ │ │ └── serde 1.0.170 0/0 0/5 0/0 0/0 0/0 ❓ │ │ └── serde 1.0.170 0/0 0/2 0/0 0/0 0/0 ❓ │ ├── randcore 0.6.4 0/0 0/5 0/0 0/0 0/0 ❓ │ └── serde 1.0.170 0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-regex 0.2.5 0/0 0/0 0/0 0/0 0/0 🔒 │ └── safe-regex-macro 0.2.5 0/0 0/0 0/0 0/0 0/0 🔒 │ ├── safe-proc-macro2 1.0.36 0/0 0/0 0/0 0/0 0/0 🔒 │ │ └── unicode-xid 0.2.4 0/0 0/0 0/0 0/0 0/0 🔒 │ └── safe-regex-compiler 0.2.5 0/0 0/0 0/0 0/0 0/0 🔒 │ ├── safe-proc-macro2 1.0.36 0/0 0/0 0/0 0/0 0/0 🔒 │ └── safe-quote 1.0.15 0/0 0/0 0/0 0/0 0/0 🔒 │ └── safe-proc-macro2 1.0.36 0/0 0/0 0/0 0/0 0/0 🔒 ├── safina-executor 0.3.3 0/0 0/0 0/0 0/0 0/0 🔒 │ ├── safina-sync 0.2.4 0/0 0/0 0/0 0/0 0/0 🔒 │ └── safina-threadpool 0.2.4 0/0 0/0 0/0 0/0 0/0 🔒 ├── safina-sync 0.2.4 0/0 0/0 0/0 0/0 0/0 🔒 ├── safina-timer 0.1.11 0/0 0/121 0/9 0/0 0/4 ❓ │ └── oncecell 1.18.0 0/0 0/5 0/0 0/0 0/0 ❓ ├── serde 1.0.170 0/0 0/7 0/0 0/0 0/0 ❓ ├── serdejson 1.0.100 0/0 0/7 0/0 0/0 0/0 ❓ │ ├── itoa 1.0.8 0/9 0/715 0/0 0/0 0/2 ❓ │ ├── ryu 1.0.14 0/0 0/5 0/0 0/0 0/0 ❓ │ └── serde 1.0.170 0/0 0/0 0/0 0/0 0/0 🔒 ├── serdeurlencoded 0.7.1 0/0 0/2 0/0 0/0 0/0 ❓ │ ├── formurlencoded 1.2.0 0/0 0/8 0/0 0/0 0/0 ❓ │ │ └── percent-encoding 2.3.0 0/0 0/7 0/0 0/0 0/0 ❓ │ ├── itoa 1.0.8 0/9 0/715 0/0 0/0 0/2 ❓ │ ├── ryu 1.0.14 0/0 0/5 0/0 0/0 0/0 ❓ │ └── serde 1.0.170 0/0 0/0 0/0 0/0 0/0 🔒 ├── temp-dir 0.1.11 0/0 0/0 0/0 0/0 0/0 🔒 ├── temp-file 0.1.7 0/0 0/0 0/0 0/0 0/0 ❓ └── url 2.4.0 0/0 0/2 0/0 0/0 0/0 ❓ ├── formurlencoded 1.2.0 0/0 0/0 0/0 0/0 0/0 ❓ ├── idna 0.4.0 0/0 0/5 0/0 0/0 0/0 ❓ │ ├── unicode-bidi 0.3.13 0/0 0/5 0/0 0/0 0/0 ❓ │ │ └── serde 1.0.170 0/0 0/20 0/0 0/0 0/0 ❓ │ └── unicode-normalization 0.1.22 0/0 0/0 0/0 0/0 0/0 🔒 │ └── tinyvec 1.6.0 0/0 0/5 0/0 0/0 0/0 ❓ │ ├── serde 1.0.170 0/0 0/0 0/0 0/0 0/0 🔒 │ └── tinyvecmacros 0.1.1 0/0 0/8 0/0 0/0 0/0 ❓ ├── percent-encoding 2.3.0 0/0 0/5 0/0 0/0 0/0 ❓ └── serde 1.0.170
0/505 0/14861 0/130 0/6 0/187
```
See rust-webserver-comparison.md.
log_request_and_response
and other logging toolingResponse::ok_200()
Response::unauthorized_401()
Response::forbidden_403()
Response::internal_server_errror_500()
Response::not_implemented_501()
Response::service_unavailable_503()
EventSender::is_connected()
PORT_env()
print_log_response
and RequestBody::length_is_known
RequestBody::len
and is_empty
to return Option
.EventSender::unconnected
.rust-webserver-comparison.md
License: MIT OR Apache-2.0