Skip to content
/ http Public

A (very) simple library for parsing http requests and generating responses in rust.

License

Notifications You must be signed in to change notification settings

Brian3647/http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

s-http 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:

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.

About

A (very) simple library for parsing http requests and generating responses in rust.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages