2个版本
0.1.1 | 2023年11月21日 |
---|---|
0.1.0 | 2023年11月21日 |
#14 in #origin
15KB
266 行
urlable
urlable
是一个基于url
crate构建的实用库,主要专注于处理与URL相关的操作。这包括但不限于
get_query
:从URL中检索查询参数,并以HashMap的形式返回。with_query
:向URL添加查询参数,将它们附加到现有的参数上。root_domain
:获取URL的根域名,常用于在服务器响应中设置根域Cookie。origin
:获取URL的原点,类似于JavaScript中的location.origin
。- ....
更多信息,请参阅文档。
lib.rs
:
使用parse
方法将input
解析为UrlAble,并在被UrlAble包装后,您可以访问更多与URL相关的功能。
use urlable::UrlAble;
let url_able = UrlAble::parse("https://ihavecoke:[email protected]:8080/x/y/z?foo=bar&z=b#id_1");
assert_eq!(url_able.hostname(), "foo.bar.com");
assert_eq!(url_able.root_domain(), ".bar.com");
assert_eq!(url_able.pathname(), "/x/y/z");
assert_eq!(url_able.port(), Some(8080));
assert_eq!(url_able.password(), "github");
assert_eq!(url_able.search(), "?invite-code=ufo-test&channel=rust");
assert_eq!(url_able.hash(), "#id_1");
assert_eq!(url_able.protocol(), "https");
let query = url_able.get_query();
assert_eq!(query.get("foo"), Some(&"bar".to_string()));
assert_eq!(query.get("z"), Some(&"b".to_string()));
依赖项
~3–4.5MB
~101K SLoC