#uri #http #slice #url

uhttp_uri

Zero-allocation parser for HTTP URIs

2 releases

Uses old Rust 2015

0.5.1 Jan 25, 2017
0.5.0 Jan 25, 2017

#81 in #uri

Download history 1/week @ 2023-11-27 4/week @ 2024-02-12 9/week @ 2024-02-19 37/week @ 2024-02-26 18/week @ 2024-03-04 14/week @ 2024-03-11

79 downloads per month
Used in 4 crates

MIT license

13KB
262 lines

uhttp_uri -- HTTP URI parser

Documentation

This crate provides a barebone, zero-allocation parser for HTTP URIs as they appear in a request header.

In general, components are extracted along defined delimiters, but further validation and processing (such as percent decoding, query decoding, and punycode decoding) is left to higher layers. In the pursuit of simplicity, this crate also contains no support for generic and non-http URIs such as file: and ftp:// – only the reduced syntax for http:// and https:// schemes is implemented.

Example

use uhttp_uri::{HttpUri, HttpResource, HttpScheme};

let uri = HttpUri::new("https://example.com:443/r/rarepuppers?k=v&v=k#top").unwrap();
assert_eq!(uri.scheme, HttpScheme::Https);
assert_eq!(uri.authority, "example.com:443");
assert_eq!(uri.resource.path, "/r/rarepuppers");
assert_eq!(uri.resource.query, Some("k=v&v=k"));
assert_eq!(uri.resource.fragment, Some("top"));

let res = HttpResource::new("/shittydogs?lang=en");
assert_eq!(res.path, "/shittydogs");
assert_eq!(res.query, Some("lang=en"));
assert_eq!(res.fragment, None);

Usage

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

[dependencies]
uhttp_uri = "0.5.1"

and importing it in the crate root:

extern crate uhttp_uri;

No runtime deps