Crates.io | tiny_http |
lib.rs | tiny_http |
version | 0.12.0 |
source | src |
created_at | 2015-05-07 13:50:16.434225 |
updated_at | 2022-10-06 16:24:54.189062 |
description | Low level HTTP server library |
homepage | |
repository | https://github.com/tiny-http/tiny-http |
max_upload_size | |
id | 2045 |
size | 191,229 |
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?
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.
Add this to the Cargo.toml
file of your project:
[dependencies]
tiny_http = "0.11"
use tiny_http::{Server, Response};
let server = Server::http("0.0.0.0:8000").unwrap();
for request in server.incoming_requests() {
println!("received request! method: {:?}, url: {:?}, headers: {:?}",
request.method(),
request.url(),
request.headers()
);
let response = Response::from_string("hello world");
request.respond(response);
}
Tiny-http was designed with speed in mind:
server.recv()
. Tiny-http will automatically rearrange the responses
so that they are sent in the right order.Connection: close
header),
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.Examples of tiny-http in use:
This project is licensed under either of
at your option.
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.