1 unstable release
new 0.1.0 | Apr 28, 2025 |
---|
#1609 in Web programming
79KB
1K
SLoC
This crate provides utilities for manipulating the path of URIs, enabling the addition of prefixes and suffixes to existing URI paths.
The crate ensures robust handling of errors and supports various URI-like types. This is
implemented with UriPathExtensions
trait for the following types:
Example
use bh_uri_utils::UriPathExtensions;
use reqwest::Url;
let url = Url::parse("https://example.com/path").unwrap();
let updated_url = url.add_path_prefix("/prefix").unwrap();
assert_eq!(updated_url.as_str(), "https://example.com/prefix/path");
let updated_url = updated_url.add_path_suffix("/suffix").unwrap();
assert_eq!(updated_url.as_str(), "https://example.com/prefix/path/suffix");
Notes
The motivation for creating this crate stems from inconsistencies in how various crates handle URI manipulations, as well as certain well-documented but unintuitive behaviors that can lead to bugs.
For example, we encountered the following unexpected situations:
-
http://localhost:3002/ + /example
resulted inhttp://localhost:3002//example
. -
http://localhost:3002/protocol/oid4vci/issuer + /.well-known/openid-credential-issuer
resulted inhttp://localhost:3002/.well-known/openid-credential-issuer
.
This crate aims to address and standardize such cases to prevent similar issues in the future.
bh-uri-utils
This library provides functionality for working with URIs for use in other The Blockhouse Technology Limited (TBTL) projects.
NOTE: If you are working outside of TBTL, you probably don't want to use this. Pick a popular URI implementation like iref or stick with the one that your web framework of choice uses.
Details
This crate is a collection of utility functions for working with URIs from different popular Rust crates in a consistent manner.
This is necessary because different URI implementations handle certain cases like appending an URI prefix differently which can lead to unexpected bugs and this crate is meant to harmonize these behaviors.
For additional documentation & examples, take a look at the crate documentation.
Changelog
The changelog can be found here.
License
Licensed under GNU Affero General Public License, Version 3.
Dependencies
~7–18MB
~261K SLoC