Skip to content

sdeleuze/mini_http

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Open in Gitpod

mini_http

Note: This project is a work in progress and shouldn't be used in any critical production environment.

A basic asynchronous* http server using mio modfied to compile to WASI.

*While network IO is performed asynchronously, handler functions are executed synchronously.

Status

Thanks to @sunfishcode and @haraldh help this should work. Notice a special mio branch is specified in the Cargo.toml.

Next step could be to update the server to handle readable and writeable events separately to not require a special Mio branch.

Usage

See examples

extern crate mini_http;

fn run() -> Result<(), Box<std::error::Error>> {
    mini_http::Server::new("127.0.0.1:3000")?
        .start(|request| {
            println!("{:?}", std::str::from_utf8(request.body()));
            let resp = if request.body().len() > 0 {
                request.body().to_vec()
            } else {
                b"hello!".to_vec()
            };
            mini_http::Response::builder()
                .status(200)
                .header("X-What-Up", "Nothin")
                .body(resp)
                .unwrap()
        })?;
    Ok(())
}

WASI system calls can be traced with RUST_LOG=wasi_common=trace wasmtime ....

About

mini async http server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 99.4%
  • Shell 0.6%