Skip to content

hangj/blocking-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Blocking HTTP server library

No async, No runtime, just a dead simple blocking http server

Usage example:

use blocking_http_server::*;

fn main() -> anyhow::Result<()> {
    let mut server = Server::bind("127.0.0.1:8000")?;

    for req in server.incoming() {
        let mut req = match req {
            Ok(req) => req,
            Err(e) => {
                eprintln!("Error: {}", e);
                continue;
            }
        };

        match (req.method(), req.uri().path()) {
            (&Method::GET, "/") => {
                let _ = req.respond(Response::new("hello world"));
            }
            _ => {
                let _ = req.respond(
                    Response::builder()
                        .status(StatusCode::NOT_FOUND)
                        .body("404 Not Found")
                        .unwrap(),
                );
             }
        }
    }
    Ok(())
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages