Crates.io | tiny_http_sccache |
lib.rs | tiny_http_sccache |
version | 0.7.0 |
source | src |
created_at | 2021-01-08 05:06:59.179729 |
updated_at | 2021-01-08 05:06:59.179729 |
description | Low level HTTP server library |
homepage | |
repository | https://github.com/tiny-http/tiny-http |
max_upload_size | |
id | 334183 |
size | 145,649 |
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.6"
Don't forget to add the external crate:
extern crate tiny_http;
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 immediatly 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 immediatly 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.