Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
tiny-http-fork
This is fork of original tiny-http.
A new development repo: codeberg
Because original authors does not respond on CVE and this crate is the only which is lightweight and actually working, I (hopefully) temporarily decided to fork the crate and keep development and support there.
The LICENSES which were initially were preserved and published under the same licenses.
Version
V 0.12.10-crate
Features
allow_utf8_headers- enables the UTF-8 support in non-standart headers.task_pool_legacy- a legacy task pool (DEFAULT)task_pool_channel- a new task pool based oncrossbeamandnix.
-- INFO/POLICY --
- AI (LLM) generated sloppy code is prohibited. AI (LLM) generates slop "a priori" (anyway).
- It is strongly discouraged from using the AI based tools to write or enhance the code. AI slope would 100% violate the license by introducing the 3rd party licensed code. This code will never be accepted.
- It is ok to use the AI (LLM) for consultation purposes i.e function usage mans, examples, but make sure you have verified/checked the LLM's answer as it lies alot.
benching
task_pool_legacy
Timer precision: 10 ns
bench fastest │ slowest │ median │ mean │ samples │ iters
├─ header_parsing_with_ascii 89.81 ns │ 7.329 µs │ 89.81 ns │ 171.1 ns │ 100 │ 100
├─ parallel_requests Server listening on 127.0.0.1:45767
Running accept thread
40.1 ms │ 79.89 ms │ 43.36 ms │ 43.83 ms │ 100 │ 100
╰─ sequential_requests Server listening on 127.0.0.1:46425
Running accept thread
14.07 µs │ 41.47 µs │ 15.88 µs │ 16.11 µs │ 100 │ 100
task_pool_legacy, allow_utf8_headers
Timer precision: 10 ns
bench fastest │ slowest │ median │ mean │ samples │ iters
├─ header_parsing_with_utf8 669.7 ns │ 12.68 µs │ 679.7 ns │ 991.3 ns │ 100 │ 100
├─ parallel_requests Server listening on 127.0.0.1:44127
Running accept thread
39.2 ms │ 62.3 ms │ 40.26 ms │ 40.74 ms │ 100 │ 100
╰─ sequential_requests Server listening on 127.0.0.1:45367
Running accept thread
14.38 µs │ 61.19 µs │ 14.67 µs │ 15.98 µs │ 100 │ 100
task_pool_channel
Timer precision: 10 ns
bench fastest │ slowest │ median │ mean │ samples │ iters
├─ header_parsing_with_ascii 88.77 ns │ 5.109 µs │ 99.77 ns │ 149 ns │ 100 │ 100
├─ parallel_requests Server listening on 127.0.0.1:39775
Running accept thread
39.19 ms │ 76.45 ms │ 41.45 ms │ 42.41 ms │ 100 │ 100
╰─ sequential_requests Server listening on 127.0.0.1:39593
Running accept thread
14.38 µs │ 393.5 µs │ 14.67 µs │ 19.78 µs │ 100 │ 100
task_pool_channel, allow_utf8_headers
Timer precision: 10 ns
bench fastest │ slowest │ median │ mean │ samples │ iters
├─ header_parsing_with_utf8 539.7 ns │ 9.858 µs │ 549.7 ns │ 650.9 ns │ 100 │ 100
├─ parallel_requests Server listening on 127.0.0.1:45301
Running accept thread
38.54 ms │ 69.38 ms │ 40.19 ms │ 40.63 ms │ 100 │ 100
╰─ sequential_requests Server listening on 127.0.0.1:43039
Running accept thread
16.39 µs │ 61.89 µs │ 16.95 µs │ 17.92 µs │ 100 │ 100
---- original readme ----
Tiny but strong HTTP server in Rust. Its main objectives are to be 100% compliant with the HTTP standard and to provide an easy way to create an HTTP server.
What does tiny-http handle?
- Accepting and managing connections to the clients
- Parsing requests
- Requests pipelining
- HTTPS (using either OpenSSL, Rustls or native-tls)
- Transfer-Encoding and Content-Encoding
- Turning user input (eg. POST input) into a contiguous UTF-8 string (not implemented yet)
- Ranges (not implemented yet)
Connection: upgrade(used by websockets)
Tiny-http handles everything that is related to client connections and data transfers and encoding.
Everything else (parsing the values of the headers, multipart data, routing, etags, cache-control, HTML templates, etc.) must be handled by your code. If you want to create a website in Rust, I strongly recommend using a framework instead of this library.
Installation
Add this to the Cargo.toml file of your project:
[]
= "0.11"
Usage
use ;
let server = http.unwrap;
for request in server.incoming_requests
Speed
Tiny-http was designed with speed in mind:
- Each client connection will be dispatched to a thread pool. Each thread will handle one client. If there is no thread available when a client connects, a new one is created. Threads that are idle for a long time (currently 5 seconds) will automatically die.
- If multiple requests from the same client are being pipelined (ie. multiple requests
are sent without waiting for the answer), tiny-http will read them all at once and they will
all be available via
server.recv(). Tiny-http will automatically rearrange the responses so that they are sent in the right order. - One exception to the previous statement exists when a request has a large body (currently > 1kB), in which case the request handler will read the body directly from the stream and tiny-http will wait for it to be read before processing the next request. Tiny-http will never wait for a request to be answered to read the next one.
- When a client connection has sent its last request (by sending
Connection: closeheader), the thread will immediately stop reading from this client and can be reclaimed, even when the request has not yet been answered. The reading part of the socket will also be immediately closed. - Decoding the client's request is done lazily. If you don't read the request's body, it will not be decoded.
Examples
Examples of tiny-http in use:
- heroku-tiny-http-hello-world - A simple web application demonstrating how to deploy tiny-http to Heroku
- crate-deps - A web service that generates images of dependency graphs for crates hosted on crates.io
- rouille - Web framework built on tiny-http
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in tiny-http by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.