Expand description
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.
Enums§
- Error
- Error type returned by
UriPathExtensions
methods.
Traits§
- UriPath
Extensions - A trait for adding prefixes and suffixes to the path component of a URI.