https://github.com/ibnz36/http
A (very) simple library for parsing http requests and generating responses in rust.
https://github.com/ibnz36/http
http rust
Last synced: 10 months ago
JSON representation
A (very) simple library for parsing http requests and generating responses in rust.
- Host: GitHub
- URL: https://github.com/ibnz36/http
- Owner: ibnz36
- License: unlicense
- Created: 2021-09-26T10:52:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-19T10:06:09.000Z (about 4 years ago)
- Last Synced: 2025-04-13T11:59:14.589Z (10 months ago)
- Topics: http, rust
- Language: Rust
- Homepage:
- Size: 23.4 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# s-http [](https://github.com/Squioole/http/graphs/contributors)
A (very) simple library for parsing http requests and generating responses.
## Usage
Add this to your `Cargo.toml` dependencies:
```
http = { git = "https://github.com/Brian3647/http" }
```
Example code:
```rs
use http::request::{HttpRequest, Method, Version, Resource};
use std::collections::HashMap;
let raw_request = String::from("GET /example HTTP/1.1\r\nHost: localhost:3000\r\nUser-Agent: rust\r\nAccept: */*\r\n\r\nhello world!");
let req: HttpRequest = raw_request.into();
let mut headers_expected = HashMap::new();
headers_expected.insert("Host".into(), "localhost".into());
headers_expected.insert("Accept".into(), "*/*".into());
headers_expected.insert("User-Agent".into(), "rust".into());
assert_eq!(Method::Get, req.method);
assert_eq!(Version::V1_1, req.version);
assert_eq!(Resource::Path("/example".to_string()), req.resource);
assert_eq!(headers_expected, req.headers);
assert_eq!("hello world!", req.msg_body);
```
## Note
This code is a modified version from https://github.com/peshwar9/rust-servers-services-apps/tree/master/chapter2/scenario1/http. Almost everything is changed, but anyways thanks to @peshwar9 for the amazing rust book.