Skip to content

axseem/http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http.rs

Simple low level HTTP library for Rust

Why?

The project was created to learn Rust and explore Hypertext Transfer Protocol.

Showcase

A minimal server that responds with a “200 OK” status to every request.

use http::{Response, Status};
use std::{io::Write, net::{TcpListener, Shutdown}, thread};

fn main() -> std::io::Result<()> {
    let listener = TcpListener::bind("127.0.0.1:8080")?;
    for stream in listener.incoming() {
        thread::spawn(move || -> std::io::Result<()> {
            let mut stream = stream?;
            let res = Response::from_status(Status::Ok);
            stream.write(&res.to_bytes())?;
            stream.shutdown(Shutdown::Both)
        });
    }
    Ok(())
}
> curl -i localhost:8080   
HTTP/1.1 200 OK

There a bit more examples in the examples directory.

About

Simple low level HTTP library for Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages