Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Low level HTTP server library in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

tiny-http/tiny-http

Repository files navigation

CrateDocumentationLicenseCI Status

Documentation

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 doestiny-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 theCargo.toml file of your project:

[dependencies]tiny_http ="0.11"

Usage

use tiny_http::{Server,Response};let server =Server::http("0.0.0.0:8000").unwrap();for requestin 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);}

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 idlefor a long time (currently 5 seconds) will automatically die.
  • If multiple requests from the same client are being pipelined (ie. multiple requestsare sent without waiting for the answer), tiny-http will read them all at once and they willall be available viaserver.recv(). Tiny-http will automatically rearrange the responsesso 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-httpwill wait for it to be read before processing the next request. Tiny-http will never wait fora request to be answered to read the next one.
  • When a client connection has sent its last request (by sendingConnection: close header),the thread will immediately stop reading from this client and can be reclaimed, even when therequest 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 notbe 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

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in tiny-http by you, as defined in the Apache-2.0 license, shall bedual licensed as above, without any additional terms or conditions.

About

Low level HTTP server library in Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp