9 releases

Uses old Rust 2015

0.1.9 Oct 19, 2018
0.1.8 Oct 17, 2018
0.1.1 Sep 28, 2018

#27 in #http-parser

36 downloads per month
Used in milstian-internet-framewo…

GPL-3.0-only

57KB
1K SLoC

Milstian-HTTP

A binary HTTP parser and generator.

License

GNU GLPv3


lib.rs:

Milstian HTTP

Milstian Logo

In progress, primarily used for learning Rust programming.

This project is used by the milstian-internet-framework to parse and build HTTP requests and responses.

Major goal

  • Easy and fast way to decode and encode HTTP requests and responses

Usage

Include in project

This crate is on crates.io and can be used by adding time to the dependencies in your project's Cargo.toml.

[dependencies]
milstian_http = "0.1.*"

And this in your crate root:

extern crate milstian_http;

Decoding a TCP stream into a HTTP request

use milstian_http::request::{Message, Method, Protocol};

let request =
    Message::from_tcp_stream(b"POST / HTTP/1.0\r\nAgent: Random browser\r\n\r\ntest=abc");
assert!(request.is_some());

let request_unwrapped = request.expect("POST HTTP1");
assert_eq!(request_unwrapped.request_line.method, Method::Post);
assert_eq!(request_unwrapped.request_line.protocol, Protocol::V1_0);

Encoding protocol, status, headers and body into a HTTP response

use milstian_http::response::Message;
use std::collections::HashMap;

assert_eq!(
    Message::new(
        "HTTP/1.0".to_string(),
        "200 OK".to_string(),
        HashMap::new(),
        b"<html><body>Nothing here</body></html>".to_vec()
    ).to_bytes(),
    b"HTTP/1.0 200 OK\r\n\r\n<html><body>Nothing here</body></html>".to_vec()
);

No runtime deps