https://github.com/mohammedgqudah/rust-http-server
A toy HTTP implementation
https://github.com/mohammedgqudah/rust-http-server
http http-server rust
Last synced: 2 months ago
JSON representation
A toy HTTP implementation
- Host: GitHub
- URL: https://github.com/mohammedgqudah/rust-http-server
- Owner: mohammedgqudah
- Created: 2024-09-19T17:30:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-02T17:36:13.000Z (over 1 year ago)
- Last Synced: 2026-01-26T21:24:02.615Z (2 months ago)
- Topics: http, http-server, rust
- Language: Rust
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HTTP In Rust
This is a toy HTTP implementation in Rust. I'm doing this solely to practice Rust.
# Example
```rust
mod http;
use http::{
request::{Method, Request},
server::Server,
};
use std::fs;
fn headers(request: &Request) -> Response {
match (request.path.as_str(), &request.method) {
("/", Method::GET) => Response {
body: fs::read("src/static/headers.html").expect("ON"),
headers: Headers::new(""),
status: Status::Ok,
},
("/", Method::POST) => {
Response {
body: "POST!".as_bytes().to_vec(),
headers: Headers::new(""),
status: Status::Ok,
}
}
_ => Response {
body: format!("
{} Not Found
", request.path)
.as_bytes()
.to_vec(),
headers: Headers::new(""),
status: Status::NotFound,
},
}
}
fn main() {
let mut server = Server::new("0.0.0.0:4000");
let _ = server.on_request(headers).listen();
}
```
# Roadmap
- [x] A single-thread blocking version
- [x] A thread pool version
- [ ] A non-blocking single-thread version
- [ ] A complete HTTP/1 and HTTP/1.1 parser
- [ ] TLS
- [ ] HTTP/2 Implementation