URL Prefix
This crate can be used to create URL prefix strings by inputting a protocol, a domain, a port number and a path.
Why You Need This?
Sometimes your web application is run on different protocols(HTTP/HTTPS) and domains. And it is boring to write some code like below to format a URL:
let mut url_prefix = String new;
if is_https else
url_prefix.push_str;
if is_https && port != 443 || !is_https && port != 80
Instead, you can easily use this crate to create URL prefix strings. For examples,
extern crate url_prefix;
let prefix = create_prefix;
assert_eq!;
extern crate url_prefix;
let prefix = create_prefix;
assert_eq!;
Validators Support
Validators
is a crate which can help you validate user input, in order to create a safe URL prefix.
To use with Validators
support, you have to enable the validator feature for this crate.
[]
= "*"
= ["validator"]
And the create_prefix_with_validated_domain
, create_prefix_with_validated_ipv4
, create_prefix_with_validated_ipv6
, create_prefix_with_validated_host
functions are available.
For example,
extern crate url_prefix;
let user_input = from_str.unwrap;
let prefix = create_prefix_with_validated_domain;
assert_eq!;
Crates.io
https://crates.io/crates/url-prefix