#http-request #header #request #http #request-line

nightly uhttp_request

HTTP request start-line and header field parsers

2 releases

Uses old Rust 2015

0.5.1 Jan 22, 2017
0.5.0 Jan 22, 2017

#5 in #headers


Used in uhttp_json_api

MIT license

15KB
223 lines

uhttp_request -- HTTP request start-line and header field parsers

Documentation

This crate provides barebone, slice-based parsers for extracting request line components and header fields from HTTP requests.

In general, components are extracted along defined delimiters, but further processing and syntax validation is left to higher layers.

Example

use uhttp_request::{RequestLine, Headers};

let req = b"GET /abc?k=v HTTP/1.1\r\nHost: example.com\r\nAccept: text/*\r\n\r\nbody";

let (reqline, rest) = RequestLine::new(req).unwrap();
assert_eq!(reqline.method, "GET");
assert_eq!(reqline.target, "/abc?k=v");
assert_eq!(reqline.version, "HTTP/1.1");

let mut headers = Headers::new(rest);

let h = headers.next().unwrap().unwrap();
assert_eq!(h.name, "Host");
assert_eq!(h.val, b" example.com");

let h = headers.next().unwrap().unwrap();
assert_eq!(h.name, "Accept");
assert_eq!(h.val, b" text/*");

assert!(headers.next().is_none());

let rest = headers.into_inner();
assert_eq!(rest, b"body");

Usage

This crate can be used through cargo by adding it as a dependency in Cargo.toml:

[dependencies]
uhttp_request = "0.5.1"

and importing it in the crate root:

extern crate uhttp_request;

Dependencies

~620KB